开发者

Single Line Linux Handler that Checks a Var and Directory Exists

开发者 https://www.devze.com 2022-12-07 21:16 出处:网络
I\'m wanting to create a one-liner in a Bash script to check if a string variable matches as well as a directory exists?

I'm wanting to create a one-liner in a Bash script to check if a string variable matches as well as a directory exists?

Currently have this, but it's fail开发者_开发技巧ing:

DEBUG="TRUE"

[[ ${DEBUG} == "TRUE" && -d /debug ]] && cp /etc/apache2/httpd.conf /debug/httpd.BEFORE.conf


Here is one possible way to write a single-line Linux command that checks if a variable and directory exist:

if [[ -n $VAR && -d $DIR ]]; then echo "Variable and directory exist"; fi

This command uses the if statement to check if the variable VAR is non-empty (-n $VAR) and if the directory DIR exists (-d $DIR). If both conditions are true, the command will print "Variable and directory exist".

0

精彩评论

暂无评论...
验证码 换一张
取 消