which CMD in csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting which CMD in csh
# 1  
Old 04-21-2010
which CMD in csh

Today I encounter one problem, I ran one script like follows:

Code:
#!/bin/csh -f

which ls

It supposes to skip the .cshrc and .login files when run this script with the "-f" option, but it does NOT.

I can see the "which" cmd first source the .cshrc ( I marked one "echo " in .cshrc ), then print out the "ls" path.
And with "-f" option, it still can inherit the ENV variables but can't get the defined variables from the current shell.

My question is
How to avoid the script to inherit the ENV variables from the current shell, or at least avoid to "source .cshrc" when ran "which" cmd?

Thanks very much
# 2  
Old 04-21-2010
Hi.

It seems to work for me (edited for readability):
Code:
Last login: Wed Apr 21 10:17:59 2010 ...
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
 .cshrc invoked, version 2010.04.21.
 .login invoked, version 2010.04.21.

vm-solaris% csh
 .cshrc invoked, version 2010.04.21.
vm-solaris% cat .cshrc

#ident  "@(#).cshrc        1.2     00/05/01 SMI"
echo " .cshrc invoked, version 2010.04.21."
umask 022
set path=(/bin /usr/bin /usr/ucb /etc .)
if ( $?prompt ) then
        set history=32
endif

vm-solaris% exit
vm-solaris% vm-solaris% csh
 .cshrc invoked, version 2010.04.21.

vm-solaris% exit
vm-solaris% vm-solaris% csh -f
vm-solaris% version =o
OS, ker|rel, machine: SunOS, 5.10, i86pc

Scripts worked the same -- no message if "-f" was supplied on shebang line.

Are you using csh or tcsh? ... cheers, drl
# 3  
Old 04-21-2010
Thanks for your reply, drl.

I am using csh, not tcsh.
'which' will have different behavior on different machines.
I tried on AIX5300, before it gave out the "ls" path, it will first source ".cshrc"; but on Debian, it's OK.

And for ENV variables, it will inherit from the parent shell no matter "-f" issued;
for normal variables, it won't inherit from parent shell if "-f" issued.
# 4  
Old 04-22-2010
Hi.

Here is the result of running on an AIX system to which I have access:
Code:
#!/bin/sh

echo
echo " System name, release, version:"
uname -s
oslevel

echo
echo " .cshrc:"
cat $HOME/.cshrc

echo
echo " Script s1, and results:"
cat s1
echo
./s1

echo
echo " Script s2, and results:"
cat s2
echo
./s2

exit 0

producing:
Code:
$ ./s0

 System name, release, version:
AIX
5.1.0.0

 .cshrc:
#ident  "@(#).cshrc     1.2     00/05/01 SMI"
echo " .cshrc invoked, version 2010.04.21."
umask 022
set path=(/bin /usr/bin /usr/ucb /etc .)
if ( $?prompt ) then
        set history=32
endif


 Script s1, and results:
#!/bin/csh

echo " Hello, world."

 .cshrc invoked, version 2010.04.21.
 Hello, world.

 Script s2, and results:
#!/bin/csh -f

echo " Hello, world."

 Hello, world.

So this works as I expect it.

I see that on AIX, the command which is itself a csh script. The first few lines are:
Code:
#!/usr/bin/csh -f
set prompt = "% "
if ( -f ~/.cshrc) then
        source ~/.cshrc
endif
...

If it's the same on your system, then I think you have the reason for the behavior you have seen ... cheers, drl

Last edited by drl; 04-22-2010 at 12:28 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with cmd while using ps

Hi i am new to shell scripting and any help is really appreciated. my requirement is in, ps -e -o pid,uname,cmd how can i split and take only the cmd part from it. I tried awk but the issue is when the cmd is returning a lengthy command which itself has some spaces it is truncating the... (7 Replies)
Discussion started by: Jojo90
7 Replies

2. Linux

Env cmd

Hello, As a workaround for certain issue, I want to use SSH with a clean environment. I tried this: env -i ssh, but it returns: env -i ssh grep: ssh: No such file or directory As I'm a beginner, it would be great if you can suggest me, what is going wrong here. Thank you, (3 Replies)
Discussion started by: Joyb25
3 Replies

3. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

4. Shell Programming and Scripting

Help with delete cmd

Is there any command to know ,how many files are deleted when rm *. cmd was excuted. I worte script which runs for 1 hours regularly and it is used to delete the .exe files but i need to know how many exe files are deleted regularly. Please let me know the cmd ---------- Post updated at... (3 Replies)
Discussion started by: kkalyan
3 Replies

5. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

6. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

7. Shell Programming and Scripting

Help with awk cmd

Hi All, I am trying to read a file as input and pull out some information from the file and put it into another file in column format and then take that file and make it an excel file. My problem is that I'm trying to put the date in one of the columns using a variable in an awk cmd, but when I... (4 Replies)
Discussion started by: New2Scripting
4 Replies

8. UNIX for Dummies Questions & Answers

mv cmd

Hi All, How can I move only files to another destination using mv cmd in hp-ux. (2 Replies)
Discussion started by: mhbd
2 Replies

9. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies

10. Shell Programming and Scripting

unix cmd

Hi i want a shell script to get the date which is mentioned in the first line of a file. file format is: #EOD rates on 20050228 at 22:06:37 -------- -------- ------- first line length is always fixed. (4 Replies)
Discussion started by: sasi
4 Replies
Login or Register to Ask a Question