Writing batch file and c++

Hi
My is c++ is for running multiple algorithms with different parameters a,b,c that has to be send when executing algorithms 1,2,3. In each run, I need to change a,b, c. The results of each different run is saved in Excel file.

My professor suggested that instead of manually running the c++ program and changing the parameters in each run, It is useful for me to write a batch file and let it run for one day then I will have considerable amount of results in the Excel file.

How could I write a batch file in Linux(Ubuntu)? Is there any example or tutorial that I can start from?
This looks like just a tutorial for writing shell scripts, which you can use to batch commands, but there are some issues in it.

> Once you have prepared your batch file, you will have to save the file with any name, but with the extension ‘.sh’ at the end of the file name.

This is not correct. A shell script doesn't need to end in .sh, and if it's something you intend to run from the command line, it probably shouldn't have an extension at all (you don't run ls.elf or zgrep.sh).

The quotes are also the special curly quote character, and not the actual quote character.

1
2
3
4
~ λ mkdir -p ~/tmp/”$(date +”%d-%m-%Y”)”
~ λ ll ~/tmp
total 0
drwxr-xr-x  2 nickchambers  admin  64 Jan  7 18:17 ””07-01-2021””/


http://mywiki.wooledge.org/BashGuide is a great resource for learning Bash (and sh) scripting as well as some of the standard utilities.

edit: they also really should use a shebang as well. I believe Linux by default will just feed it through /bin/sh if it doesn't detect any magic symbols, but it's still a good idea to be explicit.
Last edited on
I'm not a Linux user, so I defer to your expertise, uplime.
It's definitely a good topic to know about, but unfortunately too many shell scripting resources on the internet are riddled with mistakes :(
The first link I gave was a hybrid Win/Linux one. The Win portion wasn't all that bad, a bit amateurish, so I expected the Linux portion to be about the same.

That is why I added my meta search to the mix. :)
this is a great skill to have, but I have to ask why you can't put a loop in main() that does the same thing with less trouble?

I kind of have a mental wall or breakpoint. If its too complex, I will write an 'evil' system() riddled c++ "batch file" or whatever you want to call it that mixes OS calls and C++ code to do the task. If it is trivial, I will do a batch or shell script instead. The c++ ones COULD be done in shell scripting or batch, but I am not a master of those things and I can get it done faster in c++, with less clunk. Just an alternative or hybrid idea or two for you. Also, as an intermediate at best scripter, I frequently just dump one command to text and feed it to the next from a file. I know you can do it with pipes, but I can't see what went wrong as easily as I can checking the offending text file. It is very helpful for debugging, if you want to change the files to pipes later, you can.
> why you can't put a loop in main() that does the same thing with less trouble?
because it is not «less trouble»
your program already works, it solves the problem that it needs to solve. no need to bloat it with a lot of functions that the end user may never use.

you want to «test a lot of configurations», that's a different problem, so a different program may hold that responsibility.
if you want to code that wrapper in c, go ahead


do one thing and do it well.
Registered users can post here. Sign in or register to post.