LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   convert bash script to sh script? (https://www.linuxquestions.org/questions/programming-9/convert-bash-script-to-sh-script-4175417923/)

parsbin 07-21-2012 03:44 AM

convert bash script to sh script?
 
Hi
I am working on a program that i should use sh type script, now i have bash script , so how can i change bash script to sh?
i would appreciate if someone could help me to convert,
the script is :
PHP Code:

#!/bin/bash
rOut=/var/spool/asterisk/outgoing/
rUser=asterisk
rGroup
=asterisk
nFile
=call.csv
rtry
=5
mtry
=3
stime
=60

for nums in $(cat $nFile)
    do
        
num=`echo $nums | awk -F"," {'print $1'}`
        
noise=`echo $nums | awk -F"," {'print $2'}`
        
nTrunk=`echo $nums | awk -F"," {'print $4'}`

echo 
"`date`,$num,$noise>> call-log.csv
echo "Channel: DAHDI/g2/$num>> $num.call
echo "RetryTime:$rtry>> $num.call
echo "MaxRetries:$mtry>> $num.call
echo "Context: campain" >> $num.call
echo "CallerID: $num>> $num.call
echo "Extension: 300"  >> $num.call

chown $rUser
.$rGroup $num.call
mv $num
.call $rOut
sleep $stime
done 


AnanthaP 07-21-2012 05:46 AM

Code:

awk d=`date` -F"'" {
print $d, $1, $2 >> call-log.csv;
print "Channel: DAHDI/g2/" $1" >> $1.call

and so on. ie a single awk without too many variables loops, 3 awks for each line which is in a for loop etc.

.

gchen 07-21-2012 06:21 AM

1) at first line, use "#!/bin/sh" instead of "#!/bin/bas

2) try to run your script, when error occurs, fix it.

3) can use "-x" option "#!/bin/sh -x", so can get more debug information

4) can man sh to get more help (sh = bash --posix)


hope these information above are helpful for you.

: )

parsbin 07-21-2012 06:56 AM

very thanks
solved
Quote:



PHP Code:

#!/bin/sh
rOut=/var/spool/asterisk/outgoing/
rUser=asterisk
rGroup
=asterisk
nFile
=call.csv
rtry
=5
mtry
=3
stime
=60
for i in `cat call.csv`;
    do 
        echo 
"Channel: DAHDI/g2/$i>> "$i".call
        
echo "RetryTime:$rtry>> "$i".call
        
echo "RetryTime:$rtry>> "$i".call
        
echo "MaxRetries:$mtry>> "$i".call
        
echo "Context: campain" >> "$i".call
        
echo "CallerID: $i>> "$i".call
        
echo "Extension: 300"  >> "$i".call
        mv $i
.call $rOut
        sleep $stime
    done 



gchen 07-21-2012 09:26 PM

Happy to hear the news.

: )


All times are GMT -5. The time now is 09:07 PM.