tcsh I can't get script to work :(


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tcsh I can't get script to work :(
# 1  
Old 11-12-2007
tcsh I can't get script to work :(

I have an export utility that exports documents from the native file to text. This is the way I would run it from the command line:

expage "file" > "file.txt

I am trying to loop through all the documents in the directory and expage them, here is the code:

Code:
#!/usr/bin/env tcsh
foreach file ($*)
  set newname="$file.txt"
  expage "$file" > "$newname"
echo "Expaged $file to $newname"
end

Does anyone know what is wrong?
# 2  
Old 11-12-2007
In normal shell that would be

Code:
#!/bin/sh

for file in *
do
    newname="$file".txt
    expage "$file" >"$newname"
    echo "Expaged $file to $newname"
done

assuming, of course, expage is on the path.
# 3  
Old 11-12-2007
But that won't work in tcsh, right?
# 4  
Old 11-12-2007
Quote:
Originally Posted by Fred Goldman
But that won't work in tcsh, right?
Does it have to?

You can always call it from a tcsh shell script.
# 5  
Old 11-12-2007
So should I just run it the way it is or should I change the first line to:

#!/bin/tcsh
# 6  
Old 11-12-2007
Just the way I wrote it....
# 7  
Old 11-12-2007
Hi, Fred Goldman.

You didn't say what the symptoms were, so I'll assume that nothing happened -- i.e. no files were processed.

Consider a similar script:
Code:
#!/usr/bin/env tcsh

# @(#) s1       Demonstrate feature.

echo
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version tcsh
echo

foreach file ($*)
  echo " file from command line argument is $file"
end

echo
foreach file (*)
        echo " file from directory is: $file"
end

exit 0

And we will call this thusly:
Code:
% ./s1 a b c

(Versions displayed with local utility version)
tcsh 6.13.00

 file from command line argument is a
 file from command line argument is b
 file from command line argument is c

 file from directory is: readme.txt
 file from directory is: s1

Which shows that there can be a dramatic difference between "$*", and "*".

However, I agree with the implicit advice of porter: the Bourne shell family is superior to the csh family for scripting ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions in tcsh script

Hi, I have a shell script in tcsh to which I pass an argument, the length of which can vary. The possible values of the argument are the letters -c,s,i,q,a. and also a combination of these letters. (e.g: cs,si,ca,iq,qa,csq,acs,csia ..etc). The order of the letters does not matter. My problem... (2 Replies)
Discussion started by: Vaisakh P
2 Replies

2. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

3. Shell Programming and Scripting

Tcsh complete (autocomplete) script

I cant figure out how the complete function works in tcsh. 1. I whould like it to complete after writing my_program.py with either start or stop. I have tried to do something like this in .cshrc.user: complete my_program.py \ 'c/start/' \ 'c/stop/' However i cant get it to... (1 Reply)
Discussion started by: mr_cad
1 Replies

4. Shell Programming and Scripting

Help in tcsh script

Hi All, I wrote a tcsh script, but being a beginner it took me lots of efforts and on top of that I am still struggling with little modifications here and there. kindly have a loop. Line1 : I want it to run maximum of "Max" Which I am providing outside loop. So how the "for" should be... (10 Replies)
Discussion started by: nrjrasaxena
10 Replies

5. Shell Programming and Scripting

Help with gawk array, loop in tcsh script

Hi, I'm trying to break a large csv file into smaller files and use unique values for the file names. The shell script i'm using is tcsh and i'm after a gawk one-liner to get the desired outcome. To keep things simple I have the following example with the desired output. fruitlist.csv apples... (6 Replies)
Discussion started by: theflamingmoe
6 Replies

6. UNIX for Dummies Questions & Answers

Top level TCSH while Loop doen't work

Hey guys... I'm learning some shell scripting on OS X using the tcsh shell. For some reason... my while loop isn't executing right (or more likely I am doing something wrong.) Something as simple as this doesn't work: #!/bin/tcsh set g = 0 while ($g <10) echo "this" $g @ g =... (2 Replies)
Discussion started by: sprynmr
2 Replies

7. Programming

help wid C-script in tcsh

Hello Freinds I have just started off with Unix (TCSH) although I have a pretty sound background with C-programming. Kindly convey any error in foll script. #include<stdio.h> #include<math.h> #define PI 3.142857 main () { float r, A; printf("Enter the value of radius: "); scanf(" %f... (12 Replies)
Discussion started by: mahendrakamath
12 Replies

8. Shell Programming and Scripting

Help me with this tcsh script.!!!!

I need to write a tcsh script which would compare files in the two folders and then send me a mail saying which of the files are missing.For eg 1) I have this folder1 containing all the files which must land on folder2 on a daily basis. 2) If a file is present in folder1 but not in... (6 Replies)
Discussion started by: kumarsaravana_s
6 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

how to call a perl script from tcsh?

Hi I am not sure how to call a perl script from a tcsh shell. do i need to set any environment variables? your help is appreciated Thanks (1 Reply)
Discussion started by: megastar
1 Replies
Login or Register to Ask a Question