Visit Our UNIX and Linux User Community


Help in tcsh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in tcsh script
# 1  
Old 08-17-2012
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 modified,
Code:
foreach i in (0 1 2 3 .. $Max)  ????

Lin2 : I want this pause to be set as default

Line3: The "file$" is increasing each time, in the end of the loop I want to set this as default 1, i.e "file1"

Thanks in advance
Pooja


Code:
#!/bin/tcsh 
set TARGETPATH=$2
set Max=3
set Card='card_Data2011AB_Zee_40GeV'

#Function Loop                                                                                                                                                         
LINE 1 foreach i (0 1 2 3 4 5 6 7)
    echo "SHELL SCRIPTING ================ $i =============="
    cp $FILE $TARGETPATH

    if ( $i == 0 ) then
    source $TARGETPATH
    echo 'Press [Enter] key to continue...'
  LINE2  set thisvar = $<
    rm $TARGETPATH

    else if ( $i < $Max ) then
        perl -i.bak -pe 's/(file)(\d{1,})/$1 . (1 + $2)/ge' $Card
        cp $FILE $TARGETPATH
        source $TARGETPATH
        echo 'Press [Enter] key to continue...'
    set thisvar = $<
        rm $TARGETPATH

        else if ( $i == $Max ) then
LINE3           perl -pi.bak -e 's/file/file1/g' $Card                                                                                                                     
            echo "Its About To Terminate...Enjoy Scripting"
    endif
end

# 2  
Old 08-17-2012
I'd recommend to abandon tcsh (or any other *csh) and learn shell that is worth its salt (e.g. bash, ksh, zsh, ...)

https://www.unix.com/shell-programmin...d-harmful.html
# 3  
Old 08-17-2012
Hi,
thanks for the reply and for the link.
Even, I am more happier and comfortable with bash script.
Unfortunately, I have to run script on some remote machine where I am afraid only have tcsh SHELL
My little knowledge says it its UNIX machine, so both SHELL should be there. I am not sure if I can change the SHELL of some remote machine?

Thanks
Pooja
# 4  
Old 08-17-2012
Just change the first line to a different shebang:
Code:
#!/bin/bash

or
Code:
#!/bin/sh

for bourne shell.
# 5  
Old 08-17-2012
Quote:
Originally Posted by mirni
Just change the first line to a different shebang:
Code:
#!/bin/bash

or
Code:
#!/bin/sh

for bourne shell.
Unfortunately, I did not help.
I wrote the test script in my laptop with bash SHELL. and when I shifted it to the remote machine. It failed to work.
Actually, those machine are not usual one and the default environment settings pick the tcsh shell.
So I started from scratch and tryign to make it work it for tcsh.

Thanks,
Pooja
# 6  
Old 08-17-2012
What exactly do you mean "It failed to work"? Was there an error message? Post your bash version.
Check whether bash is really where I assumed it to be:
Code:
ls /bin/bash

If you let us know what system are you on, your chances for getting accurate help will be much higher than us having to guess.
Code:
uname -a

# 7  
Old 08-17-2012
Quote:
Originally Posted by nrjrasaxena
Actually, those machine are not usual one and the default environment settings pick the tcsh shell.
You don't have to care what the login shell is. The shebang line is what is used to run the script, and your machine does have sh. It must have one somewhere, too many things in UNIX demand it internally.

If you don't know where it is, which sh or whereis sh

Previous Thread | Next Thread
Test Your Knowledge in Computers #1011
Difficulty: Easy
The number 128 in base 10 equals 10000000 in base 2.
True or False?

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

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

3. Shell Programming and Scripting

tcsh env setting using shell script

Hi All, I have made a file file usercreate.sh & it has to run in tcsh env & needs some path to be set. my script is as below. ########################## #!/bin/csh setenv PATH "/usr/lib/java/class" setenv LD_LIBRARAY_PATH ########################### but when i am ruuning my script... (1 Reply)
Discussion started by: ajaincv
1 Replies

4. Shell Programming and Scripting

[Basic Query]bsh script in tcsh shell

I am a beginner (Just 2 days old:o ), i will really appreciate if you can solve my silly queries as below: Lets say i write a script like this #!/bin/bsh clear #to read name from keyboard echo "your name please.." read fname echo "you just entered $fname" exit 0 My environment is... (2 Replies)
Discussion started by: animesharma
2 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. Shell Programming and Scripting

tcsh: not run script (if: Badly formed number)

Hello I have Linux Debian & tcsh shell. My mini script not run :(. Startup script displays a message: user@host:dir% ./test if: Badly formed number. script: #!/bin/tcsh -f #script check size files systems set x = `df -h /usr | tail -n1 | awk '{ print( $5 ); }'` set y = 60% if ($x... (5 Replies)
Discussion started by: moskovets
5 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

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: #!/usr/bin/env tcsh foreach file... (8 Replies)
Discussion started by: Fred Goldman
8 Replies

9. 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

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

Featured Tech Videos