0

under /home/scrript , we have 187 bash scripts all the scripts have the following line:

kill -PIPE $PID 

we want to add the following words before this line on all the scripts as the following

[[ $KILL_STATUS = YES ]] && kill -PIPE $PID 

the reason for that is to avoid editing of each script , and use Linux commands as sed to do in one shoot on all the scripts,

1
$ for i in /home/scrript/*; do sed -i 's/kill -PIPE $PID/[[ $KILL_STATUS = YES ]] \&\& kill -PIPE $PID/' "$i"; done

Explanation

  • for i in /home/scrript/*; do FOO; done: repeat for all files in /home/scrript. N.B. depending on your shell configuration this might skip dot files.
  • sed -i 's/kill -PIPE $PID/[[ $KILL_STATUS = YES ]] \&\& kill -PIPE $PID/' "$i": for each file ("$i"), replace "in-place" (sed -i), replacing kill -PIPE $PID with [[ $KILL_STATUS = YES ]] \&\& kill -PIPE $PID. (N.B. you need to escape the & as they have a special meaning otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.