re: 5 Handy Bash Tricks in 2 Minutes VIEW POST

FULL DISCUSSION
 

Nice list.

Please please please please please use double quotes around variables, unless you explicitly desire the shell to interpret the variable value. A simple example to illustrate the issue:

$ mkdir test_shell_behavior && cd $_
$ touch 'foo' 'xyz 123'
$ for file in * ; do cp $file $file.bak; done
cp: target '123.bak' is not a directory
$ ls
foo  foo.bak  xyz 123

$ rm foo.bak
$ for file in * ; do cp "$file" "$file".bak; done
$ ls
foo  foo.bak  xyz 123  xyz 123.bak

See this Q&A on unix.stackexchange and wooledge: Quotes for more details.


You can also use man -k instead of apropos


For testing shell globs, you can use echo

$ echo cp /some/path/to/file.txt{,.bak}
cp /some/path/to/file.txt /some/path/to/file.txt.bak
 

Cool! Thanks for the feedback, that is good advice. 🤠

 

I definitly recommand ${variable}, much better to look and feel more like you can't be wrong about it :)

code of conduct - report abuse