Reputation: 1165
Hi I want grep all aliases and run their "body"
alias | grep NAME
it's return:
alias NAME123='ping google123.com'
alias NAME321='ping google321.com'
...
I want to run: ping google123.com ping google321.com but not NAME123 NAME321 All my tries ended syntax mistake.
Upvotes: 0
Views: 106
Reputation: 3833
write_aliases_script.sh
#!/bin/bash
printf "#!/bin/bash\n\n" 1>script.sh;
alias | grep NAME |
grep -o "'\(.\+\)'" |
sed "s/'//g" 1>>script.sh;
chmod +x script.sh;
# uncomment after testing
#./script.sh;
output
$ ./write_aliases_script.sh
$ cat script.sh
#!/bin/bash
ping google123.com
ping google321.com
Upvotes: 1
Reputation: 784868
Using eval you can make it run but be careful to not to invoke risky aliases:
eval $(alias | awk -F "'" '/NAME/{print $2}')
Upvotes: 0