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,
#!/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
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?
Yes, I tried using /bin/bash, but it is not working.
I am executing it something like below,
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.
you can split by separete scripts and you can use these in one script with ". script_name.sh"
#!/bin/bash
## another.bash
# bash commands
# ......
#!/bin/sh
....
.....
. ./another1.bash
. ./another2.bash
......
......
or you can invoke separete sub shells
#!/bin/sh
....
....
bash -c 'command 1
command 2
command 3'
....
....
regards
ygemici
I tried .... still no luck .....
Please find my script below,
#!/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,
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 ....
Chirel
May 23, 2011, 12:53pm
6
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
#!/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 {} \;
When I executed the script having /bin/sh shell defined, I am getting below error,
./test.sh: syntax error at line 1: `(' unexpected
however when I changed the shell to /bin/bash this is working perfectly fine.
Hi,
Then change the first line of the script from #!/bin/sh to #!/bin/bash
No ?
gr8_usk:
I tried .... still no luck .....
Please find my script below,
#!/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,
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 ....
remove LAST_CHAR line , just try this command
if [ $(sed -n '$p' $FILE|od -c|sed -n '1s/.*\(..\)$/\1/p') == "\n" ]
regards
ygemici
Chirel
May 23, 2011, 6:30pm
10
Ok, then let's begin with the begining
What is the system where you wanna do that and the shell & version.
Maybe you could show us the output of :
uname -a
ls -l /bin/sh
sed --version
od --version
awk --version
grep --version
tail --version