shell - Bash script gets printed instead of being executed -
this question similar one: http://serverfault.com/questions/342697/prevent-sudo-apt-get-etc-from-swallowing-pasted-input-to-stdin reply not satisfying (appending &&
each line of bash script not elegant) , not explain why users can paste/execute multiple subsequent apt-get install -y
commands , others can't because stdout swollen next command.
i have script my_script.sh
:
sudo apt-get install -y graphicsmagick sudo apt-get install -y libgraphicsmagick++1-dev ...
it can have 2 lines or more of sudo apt-get install
stuff. libraries (graphicsmagick, etc.) doesn't matter, can library.
when re-create script , paste it's contents bash or execute this:
cat my_script.sh | sudo -i bash
then reason first line (graphicsmagick) gets executed , rest printed console. happens sudo apt-get install -y
, other scripts, doesn't contain command behave normally.
if alter bash
sh
(which dash
) expected behaviour:
cat my_script.sh | sudo -i sh
can explain why happens?
when answering, can please avoid questions/comments:
why doing way? piping bash not safe some other aspects not safe or hackishi want know why bash
doesn't work expect , sh
does.
ps. i'm using ubuntu 14.04, sh dash can see here:
vagrant@vagrant-ubuntu-trusty-64:/tmp$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 feb 19 2014 /bin/sh -> dash
bash , dash behave different when using -i flag. bash goes interactive mode when stdin not terminal. dash on other hand not go interactive mode, -i flag.
bash shell unix sh apt
No comments:
Post a Comment