Bash, always echo in conditional statement -
this may turn out more of thought exercise, trying echo newline after command i'm executing within conditional. example, have:
if ssh me@host [ -e $filename ] ; echo "file exists remotely" else echo "does not exist remotely" fi
and want throw in echo after ssh
command regardless of outcome. reason formatting; way newline exist after prompt password ssh.
first try
if ssh me@host [ -e $filename ] && echo ;
because && echo
not change conditional outcome, bash not execute echo
if ssh
returned false. similarly,
if ssh me@host [ -e $filename ] || (echo && false) ;
does not work because short-circuit if ssh
returns true.
an answer problem be
ssh me@host [ -e $filename ] result=$? echo if [ $result == 0 ] ;
but wondering if there similar conditional expression this.
thanks.
while work
if foo && echo || ! echo;
i'd prefer putting whole thing function
function addecho() { "$@" # execute command passed arguments (including parameters) result= $? # store return value echo return $result # return stored result } if addecho foo;
Comments
Post a Comment