ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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 want to automate a process, done by a specific software. I want software do this job in the respective directories. I have some 94 directories and each directory have the respective files on which calculation needs to be done. The script that I wrote, call another file(autodock) containing instructions for specific action made on the files. But the my script not working properly.It is not changing the directory (cd command with the variable)
Here is my script:
#!/bin/bash
#this scrip automate the docking process
for DIR in `ls -ltr | awk '/^d/' | awk '{print $8}'`
do
cd ${DIR}
./autodock
done
the error is:
mazingaz:/home/puneet/Desktop/test_dock> ./ready
./ready: line 6: ./autodock: No such file or directory
./ready: line 5: cd: 2QZK: No such file or directory
./ready: line 6: ./autodock: No such file or directory
The variable seems to be working properly but why the cd is not working..far from my understanding
You have to use absolute path, either for the script ./autodock and for the directories. If you cd into one directory, you cannot change to another directory in the list if you don't go back into the previous one. And if you launch autodock from each directory a copy of it should be inside all of them. Here is a solution:
Code:
for DIR in $(find . -type d -exec readlink -f {} \;)
do
cd ${DIR}
/full/path/to/autodock
done
It should not be enough if the directory listing includes multiple levels of the subdirectories tree. Eventually
Code:
cd -
could do the trick.
If the OP wants multiple levels, his simple loop will not work anyway. He'll need a recursion. With a single list of dirs returned by his command, there's just one level.
If the OP wants multiple levels, his simple loop will not work anyway. He'll need a recursion. With a single list of dirs returned by his command, there's just one level.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.