Prev: sadc system activity collector missing from slackware 13
Next: tv card not detected; new motherboard [updated]
From: Baho Utot on 19 May 2010 20:05 I have a problem with the following bashscript, it is called from another script like this: #!/bin/bash -e set +h LFS="/mnt/lfs" CWD=$(pwd) SCRIPTS=${0%/*} STAMPS="${CWD}/Stamps" LOGS="${CWD}/Logs" PREPARE="create.lfs.tools add.lfs.user set.environment rsync.files" export LFS CWD SCRIPTS STAMPS LOGS PREPARE [ -d ${STAMPS} ] || mkdir -vp ${STAMPS} [ -d ${LOGS} ] || mkdir -vp ${LOGS} for i in ${PREPARE}; do printf "Building --> ${i}: " Chapter-04/${i}.sh done This is the problem script #!/bin/bash set +h THIS=$(basename ${0});THIS=${THIS%.sh} printf "\n" printf "\tLFS: $LFS\n\tLOGS: $LOGS\n\tSTAMPS: $STAMPS\n\tTHIS: $THIS\n" printf "\n" unset STAMPS unset LOGS [ -z ${LFS} ] && ( printf "ERROR: LFS not set\n";exit 1 ) [ -z ${STAMPS} ] && ( printf "ERROR: STAMPS not set\n";exit 1 ) if [ -z ${LOGS} ]; then printf "ERROR: LOGS not set\n" exit 1 fi printf "BARFED: should not be here\n" exit 69 This is the output when run Building --> create.lfs.tools: LFS: /mnt/lfs LOGS: /mnt/lfs/Build/Logs STAMPS: /mnt/lfs/Build/Stamps THIS: create.lfs.tools ERROR: STAMPS not set ERROR: LOGS not set Why doesn't the line: [ -z ${STAMPS} ] && ( printf "ERROR: STAMPS not set\n";exit 1 ) cause the script to exit?
From: marrgol on 19 May 2010 21:55 On 2010-05-20 02:05, Baho Utot wrote: > Why doesn't the line: > [ -z ${STAMPS} ] && ( printf "ERROR: STAMPS not set\n";exit 1 ) > cause the script to exit? Because enclosing commands in parentheses makes them being run in a subshell, so your 'exit' command exits from that subshell back to your script. Try [ -z ${STAMPS} ] && printf "ERROR: STAMPS not set\n" && exit 1 -- mrg
From: Baho Utot on 20 May 2010 04:39
marrgol wrote: > On 2010-05-20 02:05, Baho Utot wrote: >> Why doesn't the line: >> [ -z ${STAMPS} ] && ( printf "ERROR: STAMPS not set\n";exit 1 ) >> cause the script to exit? > > Because enclosing commands in parentheses makes them being run > in a subshell, so your 'exit' command exits from that subshell > back to your script. Try > > [ -z ${STAMPS} ] && printf "ERROR: STAMPS not set\n" && exit 1 > Thanks that worked |