C-Shell!! Please help...cannot get it working...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C-Shell!! Please help...cannot get it working...
# 1  
Old 06-05-2012
C-Shell!! Please help...cannot get it working...

Dear Friends,

I am trying to get a script in c-shell working but no way! I don't know why but on my mac was working and now on linux is not!

Basically the script should accept a root_file_name and work in batch on files. This is the script:

Code:
#!/bin/csh -fn

setenv IMAGIC_BATCH 1

echo "this script convert from tif to img"
echo "rootname of your file: "
set rootname = $<

echo "extention of your file: "
set ext = $<

echo "new extention of your file"
set newext=$<

echo "Options to perform: "
echo "[BA]BatchAppending [BB]BatchBoxing [BC]BatchConverting"
set choise=$<

if ( $choise =~ BA ) goto batchappending

if ( $choise =~ BB ) goto batchboxing

if ( $choise =~ BC ) goto batchconveting

batchappending:
echo "BatchAppending"
echo "Add commands"
batchboxing:
echo "BatchBoxing"
echo "add commands"

batchconveting:
echo "BatchConverting"
echo "addcommand"

set filename = ` ls $rootname*.$ext `
echo $filename
foreach i ($filename)
/opt/imagic/stand/em2em.e<<EOF
$ext
$newext
NO
NO
$i
$i"."$newext
1.56
0
EOF
end
echo -n "DONE!"

and this is the output...with many :command not found (it's like that it interprets the space as command!)

Code:
csh ./script.csh
: Command not found.
: Command not found.
this script convert from tif to img
rootname of your file: 
grafix_26042012_exp1_fr10_       
: Command not found.
extention of your file: 
tif
: Command not found.
new extention of your file
img
: Command not found.
Options to perform: 
[BA]BatchAppending [BB]BatchBoxing [BC]BatchConverting
BC
: Command not found.
: Command not found.
: Command not found.
: Command not found.
: Command not found.
BatchAppending
: Command not found.
: Command not found.
BatchBoxing
: Command not found.
: Command not found.
BatchConverting
: Command not found.
ls: No match.

foreach: Words not parenthesized.

I checked with other scripts and everything looks ok. Anyway I am not an expert..

Thanks for any help
# 2  
Old 06-05-2012
what is your system (which linux) and csh version ?
and
Code:
# od -c script.csh

# 3  
Old 06-05-2012
First of all thanks for replying...

I sorted the problem rewriting the script! Now I am puzzling with another problem..

basically the output of this script

Code:
#!usr/bin/csh -f

setenv IMAGIC_BATCH 1

echo "new script"

echo "rootname of your file: "
set rootname = $<
echo $rootname

echo "extention of your file: "
set ext=$<
echo $ext

echo "new extention of your file: "
set newext=$<
echo $newext

set filename = `ls $rootname*.$ext`
echo "These files are gonna be processed: "
echo $filename

foreach i ($filename)
/opt/imagic/stand/em2em.e <<EOF
$ext
$newext
NO
NO
$i
$i.$newext
1.56
0
EOF
end


echo "DONE!"

gives me an output like image001.tif.img and image001.tif.hed..

Can I rename the both file in the foreach cycle or I should add few lines of code? I am trying but no way... do you have any suggestions?

Thanks

---------- Post updated at 02:04 PM ---------- Previous update was at 01:58 PM ----------

I forgot to add...

image.001.tif.img should be image001.img
image.001.tif.hed should be image001.hed

basically i want to remove .tif! this for undred pics..

thanks
# 4  
Old 06-05-2012
add these (if your files like the --> "abc.tif" "abc1.tif" ....) or ?
Code:
............
foreach i ($filename)
set rootname = `echo $i|cut -d '.' -f1`
set ext = `echo $i|cut -d '.' -f2`
rm -f ${i}.hed
mv ${rootname}.${ext}.$newext ${rootname}.$newext
end
echo "DONE!"


Last edited by ygemici; 06-05-2012 at 11:31 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While within while is not working in Korn shell

Hi all, I tried to execute a while within another while, but not working. Any suggestions? Thanks in advance #!/bin/ksh typeset -i i=1 typeset -i j=1 while ] do while ] do print i = $i j= $j (( j=j+1 )) done (( i=i+1)) done (3 Replies)
Discussion started by: Soham
3 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

Shell directive not working

$ cat tmp.sh #!/tools/bin/bash echo $BASH_VERSION $ cat tmp.pl #!/usr/local/bin/perl use strict; use warnings; use DBI; use CGI; system("tmp.sh");$ tmp.sh 3.2.48(1)-release The result is as expected. $ tmp.pl 3.2.25(1)-releaseThe result is not as expected. The shell directive in... (5 Replies)
Discussion started by: carloszhang
5 Replies

4. UNIX for Dummies Questions & Answers

shell Script working

i wrote a shell program in Home Directory. and i changed to other directory. i want to try to execute shell script in Other Dir. it is not executed. how can i make this script to execute in other directory also?? Thanks, Arun (11 Replies)
Discussion started by: arun508.gatike
11 Replies

5. Shell Programming and Scripting

help- wildcard not working in shell

hi, i need to check the existence of all files starting with abc in a directory. The code works fine with a particular file name, but the file existence is not detected when i use wildcard character (abc*) kindly suggest what could be the issue :confused: src_filename1=$AI_LANDING/abc*... (11 Replies)
Discussion started by: spirit10
11 Replies

6. Shell Programming and Scripting

C shell: Working with lists

Hello Unix Gurus, I have: A list of parameters that repeat (in .txt file) Example: params.txt Series: XYZ Manufacturer: ... Software Version: ... Year made: ... Series Series: XYZ Manufacturer: ... Software Version: ... Year made: ... Series Series: ABC Manufacturer: ... ... (7 Replies)
Discussion started by: lapiduslost
7 Replies

7. Shell Programming and Scripting

Which Shell I'm working?

Hi, I'm using FreeBSD 6. I want to know which Shell I'm using. So I gave the command: -sh-3.1$ ps -p $$ PID TTY TIME CMD 15547 pts/1 00:00:00 sh Which shell is "sh"? Is it C Shell or Bourne Shell or Korn Shell? Also, are Bourne & Korn shell one and the same or are... (4 Replies)
Discussion started by: freephoneid
4 Replies

8. Shell Programming and Scripting

if -z not working in SH shell

Hello all, Any idea how to check whether a variable holding null value or not. if -z option works fine in bash, where as it is not working in sh. bash-3.00$ sh $ TEST= $ if ; then > echo "Null" > else > echo "Not null" > fi sh: test: 0403-004 Specify a parameter with this command.... (2 Replies)
Discussion started by: rijeshpp
2 Replies

9. Shell Programming and Scripting

shell not working

hi freinds, i just learning shell programming. i usually work in bash shell, but when i need tcshell, i normally i/p chshell command and go there. but although i have installed all the neccessay patches for this shell my machine can not work in tshell. but it shows the shell to be present..... (0 Replies)
Discussion started by: hytechpro
0 Replies

10. Shell Programming and Scripting

bourne shell not working

This code has worked for years and still does in my production environment. But it's failing in my development environment now. The cd works but the creation of node1, jnum, and node2 fails. Oddly the output shows a line from from the awk script at the end of the code during the setting of each... (6 Replies)
Discussion started by: gillbates
6 Replies
Login or Register to Ask a Question