3 ms·
Shell scripts frequently fail to handle directory names with spaces in them. Example from the linked article: APP_ROOT=`dirname $0` This is not going to do wha
by essrinn 13y ago
Shell scripts frequently fail to handle directory names with spaces in them. Example from the linked article:
APP_ROOT=`dirname $0`
This is not going to do what you expect if the current script is run via a command with spaces in one of the preceding directories' name.
It should be:
APP_ROOT="`dirname "$0"`"
Even this would fail if your immediate parent directory's name ended with a newline character, but should handle any other whitespace without issue.
- damncabbage 13y agoThe outer quotes aren't required: APP_ROOT=`dirname "$0"` (See http://www.tldp.org/LDP/abs/html/varassignment.html#EX16 http://www.tldp.org/LDP/abs/html/varassignment.html#EX16) Also, even if ^J or ^M were present in a parent directory's name, the command above would still work. Whitespace-like characters take some getting used to with Bash.