简体   繁体   中英

csh script foreach and symbolic link

I have created the following test1.csh and test2.csh to debug an error from link_grib.csh which is a .csh script that comes from a climate simulation software package called WRF.

I do not have superuser access on this Linux server. The provided script has run fine for a superuser on the same server so no modification should be needed.

I broke out two simple snippets from link_grib.csh, one involving foreach, and the other involving symbolic link and illustrates the output I am seeing, please see my questions below.

1) Test1.csh

#!/bin/csh
echo ${1}
foreach f ( ${1}* )
end

Output:

[frank@simunec1 20130604_mini]$ ls ./FNL.dat
./FNL.dat
[frank@simunec1 20130604_mini]$ test1.csh ./FNL.dat
./FNL.dat
foreach: No match. 

Question: Why would foreach return no match here?

2) Test2.csh

#!/bin/csh
ln -sf ./FNL.dat GRIBFILE.AAA

Output:

[frank@simunec1 20130604_mini]$ test2.csh
[frank@simunec1 20130604_mini]$ ls GRIBFILE.AAA
ls: cannot access GRIBFILE.AAA: No such file or directory  

// but running the same command outside of .csh script, everything is fine
[frank@simunec1 20130604_mini]$ ln -sf ./FNL.dat GRIBFILE.AAA
[frank@simunec1 20130604_mini]$ ls GRIBFILE.AAA
GRIBFILE.AAA

Question: Why does running the same command outside of .csh script works.

At a wild guess, you've got a .cshrc file that's changing the directory.

I'd try putting a -f in the shebang line ( #!/bin/csh -f ), or invoking the csh script using csh -f <file> .

You can use the -X option which will display commands executed in the startup scripts (the .cshrc files) which could point you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM