Operating System - Linux
1753258 Members
5284 Online
108792 Solutions
New Discussion юеВ

Using 2 kind of shell only in 1 script

 
SOLVED
Go to solution
Manuales
Super Advisor

Using 2 kind of shell only in 1 script

Hi....
can i use two shells in 1 script, i mean, like next:

#!/usr/bin/ksh
cd /home/files/
aa=`ls -l | grep earn | awk '{ print $NF }'`
#!/usr/bin/csh
echo $aa

this is because with csh i have a message error when i use awk command:
aa1=`ls -l | grep earn | awk '{ print $NF }'`: Ambiguous.

My question is:
can i use two shells at same script:
#!/usr/bin/ksh
cd /home/files/
aa=`ls -l | grep earn | awk '{ print $NF }'`
#!/usr/bin/csh
echo $aa
....
...
..
..
....
when i change kind of shell, can i continue executing command with another sintaxis depending the shell? this is in first part i want obtain a variable with awk command with ksh and then that variable i need use it with others sintaxis with other shell named csh ..can i do it? will i have some problem if i use it in this form?

Thanks, Manuales.
11 REPLIES 11
Rodney Hills
Honored Contributor
Solution

Re: Using 2 kind of shell only in 1 script

Not within the same file. You could have a ksh call out to a csh script and return the results.

It would be better to stick to one script language. "csh" has become less popular I think, and all the new enhancements are being put onto the Posix-sh, which is "ksh" like in most ways.

Rod Hills
There be dragons...
Manuales
Super Advisor

Re: Using 2 kind of shell only in 1 script

then ...
how can i use save a variable in a word invoking a command .. this is:

$(....) or `...`

because when i use csh the output is a message error: "Ambigous" and if i use ksh this run o.k.

do you know how can i save a result executed from a command in a variable?

ksh --> result=$(ls -l | awk '{ print $1 }')

chs --> ├В┬┐? can i use $(..) or `..`?? what do i use??

Thanks, Manuales.
Rodney Hills
Honored Contributor

Re: Using 2 kind of shell only in 1 script

I'm not well versed in csh. I prefer ksh myself...

Rod Hills
There be dragons...
rmueller58
Valued Contributor

Re: Using 2 kind of shell only in 1 script

You can call scripts from other scripts, I prefer ksh, bash, or bourne. Any thing I want to do I generally can write in bash or ksh and do anything that could possibly be done with csh ..

awk can be ran from within any script..

if you wanted to "kick off a subshell"

you would right a second script.. exiting the subshell becomes the problem.

Example:

Program 1:

#!/usr/bin/ksh
cd /home/files/
aa=`ls -l | grep earn | awk '{ print $NF }'`
export aa

Program 2:
#!/usr/bin/csh
echo $aa


The #!/shell command line must be in the first line of the script.

Problem exists if any other variables exist that are required may or may not be passed to the subshell.

If you "launch a shell" from with in the program eliminate the "#!" as this winds up being a Comment on any other line then line #1.

Michael Schulte zur Sur
Honored Contributor

Re: Using 2 kind of shell only in 1 script

Hi,

in csh you have to use setenv to assign variables.

greetings,

Michael
Rodney Hills
Honored Contributor

Re: Using 2 kind of shell only in 1 script

According to "man csh", the back ticks should work ok.

set aa=`ls -l | grep earn | awk '{ print $NF }'`

should not have an error under csh. Note the "set" command is required when setting csh variables.

Rod Hills
There be dragons...
OldSchool
Honored Contributor

Re: Using 2 kind of shell only in 1 script

If you want to use csh, use the set command as noted above, as in:
set aa=`ls -l | grep earn | awk '{print $NF}'

for csh use:
aa=`ls -l | grep earn | awk '{print $NF}'

The question I have, is why are you going to all this trouble to get a list of filenames into a variable?

Doesn't `ls *earn*` return the result your looking for?
OldSchool
Honored Contributor

Re: Using 2 kind of shell only in 1 script

If you want to use csh, use the set command as noted above, as in:
set aa=`ls -l | grep earn | awk '{print $NF}'

<> I meant:
for ksh use:
aa=`ls -l | grep earn | awk '{print $NF}'

The question I have, is why are you going to all this trouble to get a list of filenames into a variable?

Doesn't `ls *earn*` return the result your looking for?
Manuales
Super Advisor

Re: Using 2 kind of shell only in 1 script

what is the sintax to use "if" for csh?

if [[ ... ]]
├Г┬│r
if [ .. ]
or
if (....)
or
if (( ...))

Thanks !!!