6
0
It's nice to copy-paste a series of Bash commands that you find on a website. But depending on the commands, sometimes you lose a few. Maybe they get swallowed up by programs that read from standard input, or perhaps there's another explanation.
So I end up doing this sometimes:
$ bash <<EOF
cmd2
...
EOF
Is there a better way? Some Bash option? An SSH option? (My setup is an Bash running on an Ubuntu server, which I'm SSH'ed to from a standard OS X terminal. Not sure how much of that is relevant.)
EDIT
Example
In response to requests for a concrete example, here's one. I pasted the following four lines into an SSH shell (from my Snow Leopard desktop) connected to a stock Ubuntu Quantal running on an OpenStack VM, in the Bash shell.
sudo apt-get install -y r-base gdebi-core
sudo apt-get install -y libapparmor1 # Required only for Ubuntu, not Debian
wget http://download2.rstudio.org/rstudio-server-0.97.314-amd64.deb
sudo gdebi rstudio-server-0.97.314-amd64.deb
The first two commands executed (successfully), while the last two were apparently never received by the server (or at least, never processed by Bash).
http://stackoverflow.com/questions/10591591/linux-paste-commands-into-terminal-and-have-them-run-one-after-the-other – Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-08-25T07:57:44.603
1Do you have a specific example of what fails? – slhck – 2013-05-13T06:57:19.883
No. Usually a long-running command, like
apt-get update
,git clone
,wget
etc. – Steve Bennett – 2013-05-13T08:00:44.500Without a concrete problem description it's going to be hard to diagnose what the real issue is. I have yet to see Bash "losing" commands out of nowhere. (I also run OS X and work a lot on remote Linux machines.) – slhck – 2013-05-13T08:03:09.227
1Problem: need a convenient, robust mechanism for pasting a series of commands into a shell then executing them, that doesn't rely on the vagaries of the terminal itself. – Steve Bennett – 2013-05-13T08:05:13.300
What I meant by a concrete problem description was, for example, "I have this snippet I copy and paste, and this is what gets executed, while this is what is lost". Do you usually lose all commands after a certain one, or just some in between, etc? – slhck – 2013-05-13T08:16:33.533
you could always paste the commands into a new txt file and then execute as a script? – James – 2013-05-13T08:17:38.653
slhck: I know what you're asking for. I don't have it, and I don't think it's necessary. – Steve Bennett – 2013-05-13T08:25:15.210
James: yes, but that's even clumsier than the method I originally posted. – Steve Bennett – 2013-05-13T08:25:35.413
1
OT here, but interesting nevertheless. At least I was really surprised, that you sometimes don't get what you expect with copy&paste from websites: http://www.h-online.com/open/news/item/Old-tricks-are-new-again-Dangerous-copy-paste-1842898.html
– mpy – 2013-05-13T16:50:46.7502This reads like game of "Find me a rock"("No, that one's too big."; "No, that one's too small."; "Not that one, I don't like the color.") A more explicit problem description might get you fewer guesses and some more relevant answers you'd like better. – JRobert – 2013-05-13T17:32:51.000
@JRobert: it's more like "Find me a blue rock that weighs about the same as a cat", "No, that one is red.", "No, that weighs much more than a cat". Maybe it's a hard game, and maybe the rules aren't totally clear, but those guesses are clearly wrong. \ Also, you don't have to play :) – Steve Bennett – 2013-05-15T07:13:37.550