Note that there are some explanatory texts on larger screens.

plurals
  1. POlinux checking number of files subdirectory - providing wrong variable result when subdirectory searching for does not exist
    primarykey
    data
    text
    <p>I have created a script that goes through specific subdirectories of files and tells me how many files are in each sub-directory that start with s. My problem occurs when it is searching and the sub-directory has failed to be created. For some reason, when the sub-directory that this script is searching for does not exist, it replaces the output with another previously created variable????</p> <p>I am writing this in bash for linux.</p> <p>I am looking at the following subdirectories...</p> <pre><code>participantdirectory/EmotMRI participantdirectory/EmotMRI/firstfour/ participantdirectory/T1 </code></pre> <p>So, this is the output I should get, when the subdirectory exists and everything is ok. It is the same for all files (if it is correct).</p> <pre><code>/home/orkney_01/jsiegel/ruth_data/participants/analysis2/1206681446/20090303/14693 16 in firstfour 776 in EmotMRI folder 2 files in T1 folder </code></pre> <p>For a directory which does not have a subdirectory created, I get this output...</p> <pre><code>bash: cd: /home/orkney_01/jsiegel/ruth_data/participants/analysis2/2102770508/20090210 /14616/EmotMRI/firstfour/: No such file or directory /home/orkney_01/jsiegel/ruth_data/participants/analysis2/2102770508/20090210/14616 776 in firstfour 114 in EmotMRI folder 2 files in T1 folder </code></pre> <p>I think that, because firstfour is a subdirectory of EmotMRI, when firstfour folder hasn't been created, it substitutes the scan numbers in EmotMRI for this answer? The number of scans in EmotMRI (in this instance is correct). Here is my script below. If this is happening, how do I stop it from doing this?</p> <pre><code>for d in $(cat /home/orkney_01/jsiegel/ruth_data/lists/full_participant_list_location_may20) do if [ -d "$d" ] then gr="failed" er="failed" fr="failed" cd $d/EmotMRI/firstfour/ gr=$(ls s*| wc -l) echo " " echo "$d" echo "$gr in firstfour" cd $d/EmotMRI/ er=$(ls s*| wc -l) echo "$er in EmotMRI folder" cd $d/T1/ fr=$(ls s*| wc -l) echo "$fr files in T1 folder" cd $d/EmotMRI else echo "$d is currently not available in directory" fi done cd /home/orkney_01/jsiegel/ruth_data/ echo "Check complete" </code></pre> <p>I know you will probably have many improvements on this script, I am very new to linux. Thanks for your help, </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload