Again, use either sudo
OR su
.
It is recomended to 'not' use sudo or su inside the script.
As once the script is executeable, it becomes an 'application' or 'command', and thus can be sudo'd.
-> sudo $(which cleariptables.sh)
If you copy line by line, why do you write a script?
Execute the script to try.
The $(which APPNAME)
part is required, as the root user, which you become upon su/sudo, dont have $HOME/bin/cleariptables.sh available, so you need to invoke which to supply, or straighly use, the full path to the script.
NOTE: The $(which APPNAME) part will NOT work upon su -c '$(which appname)'
, as this one will execute the which
as root, which wont find the /home/bonafide/bin dir, despite the script in that.
Can we cosider "How to make an executable bash script" as done,
while i now want to know, is there an error in the script?
Or why do you want to make the awk a one liner?
This doesnt help read ability, and there is no use to it.
Honestly, and i dont want to be mean, 'one-liners' are for 'short' commands,pipes or very simple structures, and the more complex they are, the more advanced one should be.
Prior to attempt one liners, i highly recomend to write code that is properly syntaxed and uses idention. (regarding the script, this is achieved, but since you copied it, doesnt count)
What i wanted to say is:
Once one understands what the code does, one can go for one-liners, otherwise one just aims for unreadable / unfunctional code. (in harsh words)
Until then, one should leave one-liners to those in the know / with the skill.
To understand oneliners (get familiar to them), search for them and split them up into working! multi-liners.
Have a nice sunday!