HOW to run a bash-code in a c-shell script ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HOW to run a bash-code in a c-shell script ??
# 1  
Old 02-04-2011
HOW to run a bash-code in a c-shell script ??

Is there a way to run some code in a C-shell script by different shell, like bash?

I have that situation.
I have prepared and perfectly workable bash-skript that now I have to execute under C-shell script, divide it on steps and without creating a new files (with the bash-code parts.)

For example:
Code:
> cat c.sh
#!/bin/csh -f
echo " -- starting $0 --"
echo " .. before executing bash-code : "

/bin/bash/ -e <<END
  pair=123-456
      aRID=${pair%-*}
      iRID=${pair#*-}
  echo " aRID=$aRID; iRID=$iRID "
END

echo " -- exiting the $0 -- "
> ll c.sh
-rwxrwxrwx   1 abc1929  grsome       218 Feb  4 17:10 c.sh*
> c.sh
 -- starting ./c.sh --
 .. before executing bash-code :
pair: Undefined variable
>

Even with so simple statement it is already problems.
I need to execute much more advance and complicated processing!

I guess, the C-shell checking the syntax during the entering bash-code line in order to catch the 'END' line.
Maybe it is possible to disable it (the C-shell checking) and enable it after?

The option to have the code in single quotes is not usefull, too!
By that I would need to escape much: that will hightmаре!

Rewrite the bash script in c-shel - havy and long task!

I see only one option: brake the bash script on bansh of small files and process communication between them through env-variable or temporary files.

Disgusting solution!

Is there any other way?

Thank you!
# 2  
Old 02-04-2011
get rid of the slash and -e after /bin/bash/
Code:
/bin/bash << END

instead of
Code:
/bin/bash/ -e

# 3  
Old 02-07-2011
Quote:
Originally Posted by ilikecows
get rid of the slash and -e after /bin/bash/
Code:
/bin/bash << END

instead of
Code:
/bin/bash/ -e

So, what?! It is going to prevent CSH from validating?!
Code:
--0207-091857:~/develop/src> c.sh
 -- starting ./c.sh --
 .. before executing bash-code :
pair: Undefined variable
--0207-091858:~/develop/src> cat c.sh
#!/bin/csh -f
echo " -- starting $0 --"
echo " .. before executing bash-code : "

/bin/bash  <<END
  pair=123-456
      aRID=${pair%-*}
      iRID=${pair#*-}
  echo " aRID=$aRID; iRID=$iRID "
END

echo " -- exiting the $0 -- "
--0207-092025:~/develop/src>

Is it possible, at all, to run under csh anithing else?! So dumb shell!!
# 4  
Old 02-07-2011
Try this:
Code:
#!/bin/csh -f
echo " -- starting $0 --"
echo " .. before executing bash-code : "

/bin/bash  <<"#END"
  pair=123-456
      aRID=${pair%-*}
      iRID=${pair#*-}
  echo " aRID=$aRID; iRID=$iRID "
#END

This User Gave Thanks to Perderabo For This Post:
# 5  
Old 02-07-2011
Quote:
Originally Posted by Perderabo
Try this:
Code:
...
>/bin/bash  <<"#END"
...
"#END"

WORKS!!!!! (just it would like to have the #END in quotes: "#END".)

Whery much appreciate!!

What the staff is it? Where I can review about that?
# 6  
Old 02-07-2011
I fiddled with it until it worked for me. Quoting the marker in ksh/bash says to not process the included data. I just hoped that csh might get that right too. I don't use csh and I don't know of any great docs for it.
# 7  
Old 02-08-2011
csh references

Hi.

Many people suggest you avoid csh for scripting, scroll down the page: Csh Programming Considered Harmful. But if you must, consider the items below ... cheers, drl

Csh

TCSH: Welcome

Amazon.com: Unix C Shell Field Guide (9780139374685): Gail Anderson, Paul Anderson: Books
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you. I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I... (1 Reply)
Discussion started by: HiFuture0801
1 Replies

3. Shell Programming and Scripting

Bash code will not run

Why doesn't the code below run? Am I missing something? Thank you :). syntax() { printf "\n\n" printf "Enter HGVS description of variant(s): "; IFS="," read -a hgvs && printf "\n Nothijng entered. Leaving match function." && sleep 2 && return for ((i=0;... (5 Replies)
Discussion started by: cmccabe
5 Replies

4. Shell Programming and Scripting

How to run ksh script in bash shell?

Hi All, I have few bash shell scripts which depends on one Ksh shell script. When i run bash shell scripts, it shows error as bad interpretor : ksh no such bad file or directory. When i tried to install ksh shell, it is not downloading too. If I remove !/bin/ksh command in starting line of the... (14 Replies)
Discussion started by: Karthik03
14 Replies

5. Shell Programming and Scripting

How to make a bash or shell script run as daemon?

Say i have a simple example: root@server # cat /root/scripts/test.sh while sleep 5 do echo "how are u mate" >> /root/scripts/test.log done root@server # Instead of using rc.local to start or another script to check status, I would like make it as daemon, where i can do the following: ... (2 Replies)
Discussion started by: timmywong
2 Replies

6. Shell Programming and Scripting

How to run a bash script in csh shell?

Hi how to execute a bash script in csh shell? Thanks (3 Replies)
Discussion started by: rubinovito
3 Replies

7. UNIX for Dummies Questions & Answers

Tcl script wont run in bash shell

Hello I'm having a problem running a TCL script in my new OpenSolaris OS. When I go to the directory containing my script called 'Install' (using the gnome terminal), it doesn't seem to be able to find it even though it lists it i.e. if I type "Inst" and hit tab to complete the word, it... (11 Replies)
Discussion started by: sbsbg
11 Replies

8. Shell Programming and Scripting

General Q: how to run/schedule a php script from cron jobs maybe via bash from shell?

Status quo is, within a web application, which is coded completely in php (not by me, I dont know php), I have to fill out several fields, and execute it manually by clicking the "go" button in my browser, several times a day. Thats because: The script itself pulls data (textfiles) from a... (3 Replies)
Discussion started by: lowmaster
3 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies
Login or Register to Ask a Question