shell-scripts: Use [[ instead of [ where possible
Replace all occurrences of [ with [[ in bash and zsh scripts and configs. Performance wise it makes sense to use the builtin instead of calling an external command also when from a functionality stand point `test` would suffice.
This commit is contained in:
@@ -20,9 +20,9 @@ builtin local -a dirs files
|
||||
# All other arguments are kept.
|
||||
for arg in "$@"; do
|
||||
shift
|
||||
if [ -d "$arg" ]; then
|
||||
if [[ -d "$arg" ]]; then
|
||||
dirs+="$arg"
|
||||
elif [ -e "$arg" ]; then
|
||||
elif [[ -e "$arg" ]]; then
|
||||
files+="$arg"
|
||||
else
|
||||
set -- "$@" "$arg"
|
||||
@@ -36,7 +36,7 @@ fi
|
||||
|
||||
# Do not separate files and directories if -d flag was specified.
|
||||
while getopts d flag 2>/dev/null; do
|
||||
if [ "$flag" = "d" ]; then
|
||||
if [[ "$flag" = "d" ]]; then
|
||||
command ls "$@" -- "${files[@]}" "${dirs[@]}"
|
||||
return
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user