How to make script independent from where it is executed How to make script independent from where it is executed unix unix

How to make script independent from where it is executed


Instead of monkeying with ls and backticks and all that, just use the find command. It's built for to find files and then execute a command based on the results of that find:

 find /home/dir -name "*_1stCol.pdf" -exec mv {} /home/gmanglano/dir/columns \;

This is finding files in /home/dir that match the name *_1stCol.pdf and then moves them. The {} is the token for the found file.


Don't parse the output of ls: if you simplify the mv command to

mv /home/dir/*_1stCol.pdf /home/gmanglano/dir/columns

then you won't have an issue with being in the wrong directory.