I have a shell script (I use GNU bash 4.4.20 on Ubuntu 18.04) with a list of commands I often run, e.g.:
sudo program1 $1 foo arg1
sudo program2 $1 foo arg2
sudo program1 $1 bar arg3
sudo program2 $1 bar arg4
I'd like to grep for select lines in this script and run them. For example if I'd like to run lines 3 and 4 above with $1 set to "some_value", I was thinking something like this would work:
set some_value; grep bar my_shell_script.sh | xargs -L1
I think my problems are 1) I'm not sure how to use xargs if the command itself is embedded in the input and 2) I'm not sure how to set $1 in the context of xargs if it's receiving its input from grep.