I am new to linux and have a csh shell that isn't identifying the variables that I am trying to define. The original script is:
#! /bin/csh -fset loc = `pwd`
set stns = `ls -d RINC/`
foreach stn ( $stns )
cd $stn
if ( ! -d lowSN) then
mkdir ${loc}/${stn}lowSN
endif
if ( ! -d junk) then
mkdir ${loc}/${stn}junk
endif
if ( ! -d nodata) then
mkdir ${loc}/${stn}nodata
endif
set files = `ls *.HHZ`
foreach file ( $files )
set ff = `basename $file .HHZ`
echo ${stn}${ff}
sac ../snr_macro $ff
end
cd $loc
endff needs to be sent to a seperate program called SAC and the end of this script starts a second script that runs with SAC, which basically is answering a variety of prompts. But the variable is never properly defined. I'm not sure what to do! Thanks!
Since I am not familiar with your directory structure and data, I can only do so much. If you want to look at the directory structure in directory RINC, I think you need this: set stns = `ls -1d RINC/*`
Two issues to keep in mind:
The astric looks at everything in directory RINC
the -1 guarantees everything is listed on one line.
This ls command gives not only directories, but files also. Check the $status variable to verify whether changing to that directory actually worked. A non-zero $status is a failure:
#!/bin/csh set loc = `pwd` set stns = `ls -1d RINC/*` foreach stn ( $stns ) cd $stn >& /dev/null if ( $status == 0 ) then # if it was a good change echo $stn cd $loc # go back to current location endif end
Thanks for the idea! We ended up solving the problem by piping the variable directly into SAC. So for this chunk:
foreach file ( $files )
set ff = `basename $file .HHZ`
echo ${stn}${ff}
sac ../snr_macro $ff
end
cd $loc
endWe added the pipe to the sac line:
echo $ff | sac ../snr_macroThis seemed to transfer the variable effectively!