0

I wrote a simple python script that outputs a bunch of linux commands for a custom image manipulation command-line tool.

As an example, here is what the python script creates:

img_dae_create /d /t /19 "file1.jpg" -output "heavy" -t /mnt/img/output/
img_dae_create /d /t /7 "file2.jpg" -output "light" -t /mnt/img/output/
img_dae_create /d /t /8 "file3.jpg" -output "ex" -t /mnt/img/output/

Normally, I just copy and paste them to my Ubuntu command line and run one by one. Each command can take from 1 minute to 15+ minutes to execute.

But sometimes, the python script will generate 100s of these, and it is very tedious to copy and paste each one.

So I was wondering what would be the best command line operator to use in this case?

Would ; be better than && given that:

  • The time it takes for each command to run could be between 1 and 15 minutes.

  • The outcome of the command does not matter, if it fails, then the command line tool records that in a log file and can be dealt with later.

Thanks!

SkyeBoniwell
  • 101
  • 3
  • if it is only a couple you can put && between the commands. But for 100s of them you might want to look into making a bash script or at least split them up into smaller chunks. – totalynotanoob Oct 20 '20 at 17:40
  • @totalynotanoob thanks! So I'd create a bash script, and the copy and paste the commands with an && symbol between them? – SkyeBoniwell Oct 20 '20 at 17:41
  • The answer of the following question could be interesting for you: Why combine commands on a single line in a Bash script? – pa4080 Oct 20 '20 at 17:46
  • 1
    the && is for typing directly into the terminal. bash scripts have a different structure because they are made for completing multiple commands in a row. you should look up some tutorials to learn the syntax and structure before trying it out. – totalynotanoob Oct 20 '20 at 17:49
  • @totalynotanoob whether to use && versus separating the commands over multiple lines (or using ;) is not about command line versus script - it's about the desired logic. See for example What are the shell's control and redirection operators? – steeldriver Oct 20 '20 at 18:11
  • 1
    Think it was closed too fast... –  Oct 20 '20 at 18:14
  • @steeldriver so i my case, using command1 ; command2 ; command3; would be best right? Because I need for one command to finish before a new one is started. I also don't care about outcome, like if it fails or not, because that is recorded by the actual command-line utility that I am using – SkyeBoniwell Oct 20 '20 at 18:59
  • @bac0n the original question didn't mention choice of operators - it was just " running a bunch of command line commands one after another". It was edited after closing - you can vote to reopen if you haven't already done so. – steeldriver Oct 20 '20 at 20:11
  • I was thinking he could do something like cat | while read -r; do /path/to/$REPLY; done even change the output from the python to JSON and cat | jq | while ... that would give him some control –  Oct 20 '20 at 21:49

0 Answers0