Linked Questions
328 questions linked to/from Security implications of forgetting to quote a variable in bash/POSIX shells
2
votes
2
answers
47k
views
Bash flags based on if statements [duplicate]
I am calling a bash script that has a number of flags in the following manner:
/home/username/myscript -a -b 76
So to illustrate, the -a flag does something in myscript and the -b flag sets some ...
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 *...
-1
votes
2
answers
19k
views
Grep a variable in a file [duplicate]
A file is modified by a script using an input file-
141,141_1,BAR,HONDA,ps2_0,unassigned,ps3_0,Unassigned,ps4_0,Unassigned,ps5_0,Unassigned,ps6_0,Unassigned,ps7_3,TILL WILL,.....
Input file-
141,...
1
vote
1
answer
5k
views
Passing a variable with spaces from bash to awk [duplicate]
I am trying to pass a variable that contains spaces from bash to awk. I have simple a simple script for doing this with single string variables (in which I am searching the first column of the FILE ...
0
votes
1
answer
1k
views
Bash script to tar – Quoting issue [duplicate]
I have a script that takes filenames as positional parameters. I perform a few operations on these and then tar them. Currently my script is not working. The echo line is there for debugging ...
0
votes
0
answers
47
views
Adding spaces in a BASH variable [duplicate]
just starting out BASH and Linux in general. I've been struggling to add spaces for this variable and it'll be great help if someone could guide me here.
I tried this and didn't work"
$ line2=&...
0
votes
0
answers
43
views
Why does `if [ -d $EMPTY_VAR ]` return true? [duplicate]
I have written a Bash script which doesn't behave quite as I expected.
It contains the following lines of code.
TARGET_FOLDER=1ドル
echo "TARGET_FOLDER: $TARGET_FOLDER"
if [ ! -d $TARGET_FOLDER ...
844
votes
5
answers
391k
views
What does "--" (double dash / double hyphen) mean?
I have seen -- used in the compgen command.
For example:
compgen -W "foo bar baz" -- b
What is the meaning of the -- in there?
378
votes
6
answers
420k
views
Why does my shell script choke on whitespace or other special characters?
... or an introductory guide to robust filename handling and other string passing in shell scripts.
I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
287
votes
5
answers
78k
views
Why is using a shell loop to process text considered bad practice?
Is using a while loop to process text generally considered bad practice in POSIX shells?
As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
213
votes
6
answers
337k
views
How can we run a command stored in a variable?
$ ls -l /tmp/test/my\ dir/
total 0
I was wondering why the following ways to run the above command fail or succeed?
$ abc='ls -l "/tmp/test/my dir"'
$ $abc
ls: cannot access '"/tmp/test/my': No such ...
95
votes
9
answers
303k
views
Can sed replace new line characters?
Is there an issue with sed and new line character?
I have a file test.txt with the following contents
aaaaa
bbbbb
ccccc
ddddd
The following does not work:
sed -r -i 's/\n/,/g' test.txt
I ...
Jim's user avatar
- 10.6k
182
votes
1
answer
81k
views
When is double-quoting necessary?
The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of $...
98
votes
5
answers
144k
views
How do I recursively delete directories with wildcard?
I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple*. How would I go ...
61
votes
7
answers
79k
views
Setting IFS for a single statement
I know that a custom IFS value can be set for the scope of a single command/built-in. Is there a way to set a custom IFS value for a single statement?? Apparently not, since based on the below the ...