#!/bin/sh
sum=0
for file in `ls `
do
if [ -f $file ]
then
size=`ls -l $file | awk ' {print $5}'`
sum=`expr $sum + $size`
fi
done
echo "$sum"
6 Replies - 910 Views - Last Post: 14 May 2012 - 04:09 AM
#1
How do I translate this Korn Shell script to C-Shell?
Posted 13 May 2012 - 08:31 PM
Does anybody know how to translate this Korn Shell script into a C-Shell script??
Replies To: How do I translate this Korn Shell script to C-Shell?
#2
Re: How do I translate this Korn Shell script to C-Shell?
Posted 13 May 2012 - 08:33 PM
I don't see why that wouldn't run under the C-Shell. Your Shebang isn't even shell specific.
#3
Re: How do I translate this Korn Shell script to C-Shell?
Posted 14 May 2012 - 01:45 AM
no2pencil, on 14 May 2012 - 05:33 AM, said:
I don't see why that wouldn't run under the C-Shell. Your Shebang isn't even shell specific.
The C-Shell isn't Bourne Shell compatible and has quite different syntax. So there's plenty of things in the script that won't run in the C shell.
@OP:
The syntax to set a variable in csh is set VARIABLE = VALUE. The syntax for a for loop is:
foreach VARIABLE in (ITEMS)
stuff
end
The syntax for an if-statement is:
if(CONDITION) then
stuff
end
The expression to check for a file is -f FILENAME, just like in test. The syntax to set a variable to the result of an expression is @ VARIABLE = Expression.
That should be everything you need to convert your script to csh.
#4
Re: How do I translate this Korn Shell script to C-Shell?
Posted 14 May 2012 - 02:15 AM
sepp2k, on 14 May 2012 - 01:45 AM, said:
no2pencil, on 14 May 2012 - 05:33 AM, said:
I don't see why that wouldn't run under the C-Shell. Your Shebang isn't even shell specific.
The C-Shell isn't Bourne Shell compatible and has quite different syntax. So there's plenty of things in the script that won't run in the C shell.
@OP:
The syntax to set a variable in csh is set VARIABLE = VALUE. The syntax for a for loop is:
foreach VARIABLE in (ITEMS)
stuff
end
The syntax for an if-statement is:
if(CONDITION) then
stuff
end
The expression to check for a file is -f FILENAME, just like in test. The syntax to set a variable to the result of an expression is @ VARIABLE = Expression.
That should be everything you need to convert your script to csh.
Thank you sepp2k...that was very helpful. I am truly grateful.
#5
Re: How do I translate this Korn Shell script to C-Shell?
Posted 14 May 2012 - 03:53 AM
no2pencil, on 13 May 2012 - 10:33 PM, said:
Your Shebang isn't even shell specific.
WTF? sh IS Bourne shell.
Granted, some Linux flavors will alias it off to Bourne compatible shells, usually bash but now often ash. However, if you really want bash functionality, you should be using bash. The sh is Bourne.
That said, why in the world would anyone willingly use C-Shell...
#6
Re: How do I translate this Korn Shell script to C-Shell?
Posted 14 May 2012 - 03:56 AM
baavgai, on 14 May 2012 - 06:53 AM, said:
My understanding (& please, correct me if I'm wrong), you plug your shell in the Shebang :
/bin/ksh or /bin/korn93 for korn
/bin/bash for bash
However if you just use the shell of the currently logged in session, you use /bin/sh, as it is not specific. So if someone codes a script in korn, & they log in with C-shell, the Shebang of /bin/sh will point to C-shell. Or am I wrong on this?
#7
Re: How do I translate this Korn Shell script to C-Shell?
Posted 14 May 2012 - 04:09 AM
no2pencil, on 14 May 2012 - 12:56 PM, said:
However if you just use the shell of the currently logged in session, you use /bin/sh, as it is not specific. So if someone codes a script in korn, & they log in with C-shell, the Shebang of /bin/sh will point to C-shell. Or am I wrong on this?
Yes, you are. If the shebang says /bin/sh, the script will be opened with /bin/sh¹ (that is the executable file (or symlink) "sh" that lies in the directory "/bin"). As baavgai said /bin/sh might be a symlink to bash or ash (or any other bourne-compatible shell), or it might be its own executable. Either way that does not depend on the shell with which you're currently logged in.
¹ Assuming it's invoked directly, i.e. `/path/to/the/script` or `./script` (or `script` if the script lies somewhere in the $PATH). If you invoke the script as `sh script` or `bash script` etc., it will be opened with that shell of course.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|