Home > Net >  How to use ls function in Unix while the script and the files are not in the same directory
How to use ls function in Unix while the script and the files are not in the same directory

Time:10-20

I have a folder that contains several subfolders, such as PROGRAMME, containing the scripts and URLS, containing the pure text files and TABLEAUX is the subfolders for output.

You can see the detail in the image 1.

Now I need to ls the subfolder URL and write to the subfolder TABLEAUX. However, when I use the function ls in for loop, it's said:

ls: cannot access 'URLS': No such file or directory

I guess it's because that the script and the subfolder are not in the same place and I've changed the directory to where the script is (if not, I can't execute the script.) like it shows in the image 2.image2

And my codes are here:

#command: bash <name of script.sh> <folder_input> <folder_output>

dossier_url=$1
dossier_tableaux=$2
echo $dossier_url
echo $dossier_tableaux       # it's ok until here
for fichier in $(ls $dossier_url); do
echo $fichier;
done                # Ubuntu shows "ls: cannot access 'URLS': No such file or directory"

CodePudding user response:

Sauvé !

I shouldn't change directory to PROGRAMMES but should use the command:

bash PROGRAMMES/<name of scipt.sh> <input> <output>
  • Related