Shell script running command in different shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script running command in different shell
# 1  
Old 05-23-2011
Shell script running command in different shell

Hi All,

Is there any way where we can run few commands with different shell in a shell script ?

Let's have an example below,

My first line in script reads below,

Code:
#!/bin/sh

However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few commands.

Can you please help me to achieve this.

Regards,
Uday
# 2  
Old 05-23-2011
Depending on how extensive you need the subshell to be, you might just be able to invoke it by prefacing your command with /usr/bib/bash, etc...

Had you tried anything so far?
# 3  
Old 05-23-2011
Yes, I tried using /bin/bash, but it is not working.

I am executing it something like below,

Code:
LAST_CHAR=`/bin/bash od -An -tc -j $(( $(ls -l $FILE  | awk '{print $5}') - 1 )) $FILE | awk '{print $1}' | sed '/^$/d'`

And it is failing.

Please help.
# 4  
Old 05-23-2011
you can split by separete scripts and you can use these in one script with ". script_name.sh"

Code:
#!/bin/bash
## another.bash
# bash commands
# ......

Code:
#!/bin/sh
....
.....
. ./another1.bash
. ./another2.bash
......
......

or you can invoke separete sub shells

Code:
#!/bin/sh
....
....
 
bash -c 'command 1
command 2
command 3'
....
....

regards
ygemici
# 5  
Old 05-23-2011
I tried .... still no luck .....

Please find my script below,

Code:
#!/bin/sh
set -x
TREE="$1"
cd $TREE
for FILENAME in FILE1 FILE2 FILE3
do
        ABS_NAME=`find $TREE -name $FILENAME -print -follow  2>/dev/null`
        dir_name=`dirname ${ABS_NAME}`
        FILE=`basename ${ABS_NAME}`
        cd $dir_name
        LAST_CHAR=`od -An -tc -j $(( $(ls -l $FILE  | awk '{print $5}') - 1 )) $FILE | awk '{print $1}' | sed '/^$/d'`
        if [ "${LAST_CHAR}" != "\\n" ]
        then
                echo "New line character is missing in $FILE."
        else
                echo "$FILE ok"
        fi
done

I wanted to use "/bin/bash" for below line in script,

Code:
LAST_CHAR=`od -An -tc -j $(( $(ls -l $FILE  | awk '{print $5}') - 1 )) $FILE | awk '{print $1}' | sed '/^$/d'`

---------- Post updated at 08:32 PM ---------- Previous update was at 08:30 PM ----------

Basically the above line should get executed with /bin/bash shell as /bin/sh is having some limitations ....
# 6  
Old 05-23-2011
Hi,

What kind of limitations ?
I don't see anything on this line that should work better with bash than with any other shells. . .

---------- Post updated at 06:53 PM ---------- Previous update was at 06:20 PM ----------

Anyway, maybe you could try
Code:
#!/bin/sh
DIRNAME="$1"
find $DIRNAME \( -name 'FILE1' -o -name 'FILE2' -o -name 'FILE3' \) -exec sh -c 'tail -c 1 "$1" | grep -qP "\n" && echo "$(basename "$1") OK" || echo "New Line is missing in $(basename "$1")"' X {} \;

# 7  
Old 05-23-2011
When I executed the script having /bin/sh shell defined, I am getting below error,

Code:
./test.sh: syntax error at line 1: `(' unexpected

however when I changed the shell to /bin/bash this is working perfectly fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
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

Running 3 shell script parallel in another shell script

Hi, I'm trying to do teh below thing. I have a single script which uses 3 different parameters to do 3 different work like belwo. test1.sh par1 -- it shuts down an instance test1.sh par2 -- it shuts down an instance test1.sh par3 -- it shuts down an instance Now I created a script... (7 Replies)
Discussion started by: bhaski2012
7 Replies

4. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

5. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

6. Solaris

Error during running sqlplus command from shell script in Solaris

I am using following code to connect to oracle database from solaris shell script. which will try thrice to connect the database ...at the 4rth atempt it will exir=t. count=0 while ; do sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile WHENEVER OSERROR EXIT 9; WHENEVER SQLERROR... (4 Replies)
Discussion started by: millan
4 Replies

7. Shell Programming and Scripting

running shell command in Perl script

Does not work. #!/usr/bin/perl $etcdir = 'ls -l /etc'; print $etcdir; #END ------------result-------- #perl -w abc123.pl ls -l /etc # This method works. #!/usr/bin/perl $etcdir = system("ls -l /etc"); print $etcdir; #END (2 Replies)
Discussion started by: dplinux
2 Replies

8. Shell Programming and Scripting

Need to Write Shell Script based off of this shell command

I'm trying to read a bunch of log files and output the lines that contain particular strings. To accomplish this, I've been running the following from the command line: find . -name "*" | xargs grep " " | grep " " > output.txt Two grep statements are needed in case I'm looking for a... (3 Replies)
Discussion started by: Rally_Point
3 Replies

9. UNIX for Dummies Questions & Answers

running command prompt executable file in shell script

hi i have file extentioned with test.vbs. i am able to run this file n execute through command promt but i dont know how to run in shell script example: file name is test.vbs which contains strSoundFile = "C:\windows\Media\Notify.wav" Set objShell = CreateObject("Wscript.Shell") strCommand... (5 Replies)
Discussion started by: atl@mav
5 Replies

10. Shell Programming and Scripting

URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 Replies
Login or Register to Ask a Question