escaping - Bash missing ']' error for output -
i wrote function in ~/.bashrc file clean configuration files of comments. function follows:
clean_config() { [ -z "$2"] && cleanchar="#" || cleanchar="$2" egrep -v "^[[:space:]]*${cleanchar}|^$" "$1" | uniq } basically states if user doesn't pass 2nd argument, use # comment character , clean. first argument file itself. function "works" when run ; character clean, following:
[root@server]: /etc/php5/fpm/pool.d # clean_config www.conf \; bash: [: missing `]' [www] user = www-data group = www-data listen = /var/run/php5-fpm.sock listen.owner = www-data listen.group = www-data it escapes character fine, bash: [: missing ']' line @ top. i've tried changing [[ -z "$2"]] causes bash.bashrc not load @ all.
any ideas? version info below:
[root@server]: ~ # bash --version | head -n1 gnu bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
the space before closing ] not optional:
[ -z "$2" ] # ^ without it, command ok when $2 empty, becomes [ -z ].
the same applies [[ ... ]], don't have quote variables inside:
[[ -z $2 ]]
Comments
Post a Comment