Linked Questions
805 questions linked to/from Why does my shell script choke on whitespace or other special characters?
1
vote
1
answer
29k
views
Bash script: array elements containing space character [duplicate]
I'm getting started with bash scripting. I'm working with array elements that contain space characters. In the code below, the third array element is "Accessory Engine". I tried to set the space ...
4
votes
2
answers
5k
views
Using files that have spaces in their name in pipes [duplicate]
I have folder named play which contains a file damn file (with space). When I use find and pipe the output to tar:
find play/ -name 'damn*' | tar cf archive.tar -T -
It works perfectly. Why does this ...
3
votes
1
answer
4k
views
Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of *...
2
votes
2
answers
10k
views
printf escape %q string vs variable [duplicate]
I would like to escape path with white space which works fine when I use it directly like this:
$ printf '%q' "/path/to/first dir/dir/"
/path/to/first\ dir/dir/
When I use a variable instead of ...
5
votes
1
answer
8k
views
Storing whitespace in a shell script variable [duplicate]
I need to store specific number of spaces in a variable.
I have tried this:
i=0
result=""
space() {
n=$1
i=0
while [[ "$i" != $n ]]
do
result="$result "
((i+=1))
...
1
vote
1
answer
7k
views
"while read -r LINE; do" is replacing multiple spaces with a single space [duplicate]
I am trying to read in a file using read in bash 3.2, but read seems to be converting any instance of multiple whitespace into a single space.
For example, the code below has two tabs between "hello" ...
0
votes
1
answer
17k
views
Problems copying files with spaces inside the file name in a bash script [duplicate]
I have the following function inside a BASH script (running under Ubuntu 12.x), which would copy over a file with spaces inside the file name. It's not working. I've tried many different combinations, ...
3
votes
3
answers
3k
views
Bash: escaped quotes in subshell [duplicate]
When I execute the following command:
#!/bin/bash
while IFS= read -r -d '' file; do
files+=$file
done < <(find -type f -name '*.c' -print0)
echo "${files[@]}"
I do not get the same result ...
2
votes
2
answers
790
views
bash: can't set a variable to a solid string [duplicate]
I cannot set a variable with a whole command-string as following:
A="/bin/ps wwwaux"
for a in $A
do
echo "$a"
done
It assigns array instead of solid string someway.
My environment:
GNU/Linux, ...
1
vote
2
answers
12k
views
Input variables with spaces? [duplicate]
Say I have a script that has:
command $1
Also say command has an optional parameter so it could also be command $1 $2.
What happens if $1 includes a space here (let us assume $1=A B)? Will command ...
0
votes
1
answer
10k
views
[: =: unary operator expected [duplicate]
I need to write a script to test if a service inside of an Android emulator is ready for apk installation or not using this command
adb -s emulator-5554 shell pm list package | grep package:com....
1
vote
2
answers
2k
views
Rename a file dynamically containing spaces [duplicate]
I want to rename a file dynamically based on data which contains spaces
Name="Abc DEF"
Name1="GHI JKL"
mv /sample/pdf/noriginalName.pdf /sample/outputPdf/${NAME}${Name1}".pdf"
But it gives me an ...
1
vote
1
answer
10k
views
How to pass a parameter with space in nohup? [duplicate]
I have script to run a jar, like shown below.
user="Tim Tom";
jarfile=./app.jar
SC_CD="java -jar -Xms512m -Xmx2048m -DUSER='$user' $jarfile"
nohup $SC_CD
And im geeting error message as
Error: ...
2
votes
2
answers
2k
views
Echoing/printing a bash `ls` command substitution without quotes [duplicate]
I have the following example:
$ a="$(ls)"
$ echo $a
backups cache crash lib local lock log mail opt run snap spool tmp
$
$ echo "$a"
backups
cache
crash
lib
local
lock
log
mail
...
2
votes
2
answers
3k
views
How to handle spaces in path names when variable contains multiple paths [duplicate]
Although I've read myself through most of the questions about handling spaces in path names, I haven't found my case yet, which is about several path names in one variable.
find will need this when ...