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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -