Monday, May 6, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 5709  / 2 Years ago, thu, september 1, 2022, 2:24:01

I keep some bash snippets and copy&paste them when I needed for management.
But I discovered apt-get cancels script execution.
Here's my script where problematic.



apt-get -y install gcc g++ make cmake perl

cd ~/
mkdir t1
cd t1


I copy & paste this script on OS X Terminal to Ubuntu 12.04 LTS server (fresh install on VM) Script always stop after apt-get finished.



I run this command with root account like this.



ssh user1@server

<password…>

sudo su

<password…>

apt-get -y install gcc g++ make cmake perl

cd ~/
mkdir t1
cd t1


Can this be a problem? Or why my script stops after apt-get finished, and how to make it to continue?


More From » command-line

 Answers
5

First off, you're not running a script. Pasting a series of commands doesn't make a script. As described in Jobin's answer, you would not have this problem if you were actually using a script.



The problem is probably that you're overloading the input buffer with the commands and hoping that bash is the next process to read from the input buffer. There are a lot of reasons that apt-get would read from the input buffer instead, so nothing is left when it finishes and drops you back to bash.



If you want, you can still paste a series of commands without going to the trouble of copying or writing a script file and making it executable. (Creating the script would be a waste of effort in many cases, for example a simple set of commands that you have to do on multiple machines and never twice on the same machine.)



If you paste the series of commands separated by semicolons, the whole sequence gets fed to bash and will continue regardless of what apt does with the input buffer:



apt-get -y install gcc g++ make cmake perl; cd ~/; mkdir t1; cd t1


[#28514] Saturday, September 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
utilitere

Total Points: 394
Total Questions: 110
Total Answers: 114

Location: Solomon Islands
Member since Wed, Mar 29, 2023
1 Year ago
;