osx - Bash command substitution stdout+stderr redirect -


good day. have series of commands wanted execute via function exit code , perform console output accordingly. being said, have 2 issues here:

1) can't seem direct stderr /dev/null.

2) first echo line not displayed until $1 executed. it's not noticeable until run commands take while process, such searching hard drive file. additionally, it's obvious case, because output looks like:

sh-3.2# ./runscript.sh sh-3.2# com.apple.auditd: loaded sh-3.2# attempting... enable security auditing ...success 

in other words, stderr displayed before "attempting... $2"

here function trying use:

#!/bin/bash function savechange {     echo -ne "attempting... $2"     exec $1     if [ "$?" -ne 0 ];         echo -ne " ...failure\n\r"     else         echo -ne " ...success\n\r"     fi }  savechange "$(launchctl load -w /system/library/launchdaemons/com.apple.auditd.plist)" "enable security auditing" 

any or advice appreciated.

this how redirect stderr /dev/null

command 2> /dev/null 

e.g.

ls -l 2> /dev/null 

your second part (i.e. ordering of echo) -- may because of have while invoking script. $(launchctl load -w /system/library/launchdaemons/com.apple.auditd.plist)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -