Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am using imagemagick and need to excecute a simple command in different directories. Because the command takes some time I would have to enter it... then wait then , once its done (beacuse parallel would crash the system), change the folder , enter commandline again, etc you get the picture.
I m looking for a way that I could do that automatically.
so the process is
cd a
montage something make asomething
cd ..
cd b
montage something make bsomething
etc
How could i enter that(commandline folderchange; command line folder change) in the terminal so i could get it to just run all night?
A bash script is just a regular terminal. The commands would be the same as you would type in the terminal
just add #!/bin/bash to the top of your script and type exactly what you would type if you were entering the commands in yourself
If you were doing it manually with the commands:
cd a
montage something make asomething
cd ..
cd b
montage something make bsomething
etc
put that right in the bash script. You can cd in a bash script, you can do anything you could normally do at a terminal. There is no extra syntax. Is this what you're asking? Or am I understanding wrong?
You can also just put it all in one line on the command line:
Code:
cd a && montage something && make asomething && cd .. && cd b && montage something && make bsomething
The "&&" between each command means that the next command will execute only if the previous command was successful. If you don't care if the previous command was successful and just want the next command to execute no matter what, use ";" instead of "&&".
A script of what I typed would look like the following, just one command on each line.
Code:
#!/bin/sh
cd a
montage something
make asomething
cd ../b
montage something
make bsomething
This script would be similar to you just putting a ";" between commands instead of "&&". You can (should) also combine the "cd .. && cd b" to just "cd ../b".
If you create a list of directories with files to be processed, then you could loop thru that list.
Code:
((dirlist is a file containing all the directory name))
while read dirname; do
cd $dirname
<<do stuff with imagemagick>> (Insert valid code here)
done < dirlist
The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.