How to read a space in bash - read will not

2015-03-02T07:54:28

Many people have shown how to keep spaces when reading a line in bash. But I have a character based algorithm which need to process each end every character separately - spaces included. Unfortunately I am unable to get bash read to read a single space character from input.

while read -r -n 1 c; do printf "[%c]" "$c" done <<< "mark spitz" printf "[ ]\n"

yields

[m][a][r][k][][s][p][i][t][z][][ ]

I've hacked my way around this, but it would be nice to figure out how to read a single any single character. Yep, tried setting IFS, etc.

Copyright License:
Author:「user3546411」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/28800740/how-to-read-a-space-in-bash-read-will-not

About “How to read a space in bash - read will not” questions

Many people have shown how to keep spaces when reading a line in bash. But I have a character based algorithm which need to process each end every character separately - spaces included. Unfortuna...
I am using bash. $ bash --version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later &lt;http://...
Say the following Bash script: #!/bin/bash export TEXTDOMAINDIR=./locale export TEXTDOMAIN=test-gettext-read . gettext.sh echo -n $(gettext "Insert a word: ") read word GNU gettext is used to m...
I am a new bash learner. I want to know, how to take a list of string from standard input? After taking all of the strings, I want to print them space separated. Say the input is like the followin...
I am trying this small piece of code in bash: echo "Enter number(a b c)" read natc echo ${natc[1]} The input should be 3 number in one line, space delimited, read from stdin, e.g. 4 5 6 and I wo...
Not sure if I should put this on stackoverflow or unix.stackexchange but I found some similar questions here, so here it goes. I'm trying to create a script to be called by .bashrc that allows me to
I'm new on bash and I'm trying to write a bash script that will save user's multilines inputs (a text with newlines, somes lines of code, etc.). I need to allow newline (when you press "Enter"),
#!/bin/bash read k read m read fileName head -n -$k $fileName | tail -n +$m $fileName Hi, this is what I have now. I have to create bash interpreter that removes the lines from head and removes l...
Problem: I need to input two vars on BASH by space: How to split it by space? On Python i can use function &quot;split&quot;: a, b = input().split(&quot; &quot;) Input data: 12 14 1 2 3 ...
I'm trying to write a bash script that read user's input (some files so user can use TAB completion) and copy them into a specific folder. #/bin/bash read -e files for file in $files do echo $...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.