bash:! ": event not found
$ echo "hi \!" hi \!
echo 'Hello World!'
histexpand parameter. This can be done with the set +H or set +o histexpand :set + H echo "Hello World!"
mp3info -t "Don't Let It Show" ... mp3info -t "Ah! Leah!" ...
set +H in my .bashrc. But this is a matter of habit and everyone decides for himself.$* and $@ not exactly what you need: after substituting the parameters, they become a word list, passed in arguments, not a list of parameters separately.for arg in "$ @"
for arg
for arg matches for arg in "$@" . Enclosed in double quotes, the variable "$@" is special "$@" converted to a list of "$1" "$2" "$3" , etc. This trick will work in most cases.#! / bin / bash # wrong for x in $ *; do echo "parameter: '$ x'" done
$ ./myscript 'arg 1' arg2 arg3 parameter: 'arg' parameter: '1' parameter: 'arg2' parameter: 'arg3'
#! / bin / bash
# right!
for x in "$ @"; do
echo "parameter: '$ x'"
done $ ./myscript 'arg 1' arg2 arg3 Parameter: 'arg 1' parameter: 'arg2' parameter: 'arg3'
function keyword with parentheses () when defining a function.function and () at the same time, but you cannot do that in any other shell. Some interpreters, however, will accept function foo , but for maximum compatibility it is better to use: foo () {
...
} echo will print ~ to stdout instead of listing the user's home directory.$HOME instead of ~ ."~ / dir with spaces" # "~ / dir with spaces" ~ "/ dir with spaces" # "~ / dir with spaces" ~ / "dir with spaces" # "/ home / my photos / dir with spaces" "$ HOME / dir with spaces" # "/ home / my photos / dir with spaces"
local itself works as a command. Sometimes it may in an incomprehensible way interact with the rest of the string. For example, if in the following command you want to get the return code ($?) Of the substituted command, you will not get it: the return code of the local command overlaps it.local varname varname = $ (command) rc = $?
Source: https://habr.com/ru/post/48053/
All Articles