Sponsored Content
Full Discussion: Convert a bash to ash
Operating Systems Linux Ubuntu Convert a bash to ash Post 302936434 by Scrutinizer on Wednesday 25th of February 2015 11:40:32 AM
Old 02-25-2015
In addition to suggested checkscript the script, there are a couple more in the original script:
Code:
 grep -En '==|\[\[|\[[0-9@]\]|=\(|\$\[|=~' script
80:    if [ ! "x$curl" == "x" ];then
118:    if [ $2 ] && [ "$status" == "0" ];then
156:if [ "x$url" == "x" -o "x$token" == "x" ]
162:if [[ `which curl` =~ "/curl" ]]
166:if [[ `which wget` =~ "/wget" ]]
171:if [[ ! $curl && ! $wget ]];
180:    if [ "$host" == "" ] || [ "$State" == "" ]; then
200:        arr=($line)
201:        if [ ${#arr[@]} != 0 ];then
202:            if [[ ${#arr[@]} < 3 ]] || [[ ${#arr[@]} > 4 ]];then
203:                echo "ERROR: STDIN must be either 3 or 4 fields long, I found "${#arr[@]}
205:                if [ ${#arr[@]} == 4 ]; then
207:                    <servicename>${arr[1]}</servicename>
208:                    <hostname>${arr[0]}</hostname>
209:                    <state>${arr[2]}</state>
210:                    <output>${arr[3]}</output>"
213:                    <hostname>${arr[0]}</hostname>
214:                    <state>${arr[1]}</state>
215:                    <output>${arr[2]}</output>"
219:                checkcount=$[checkcount+1]

replace all echo statements with:
Code:
printf "%s\n" "some line"

replace
Code:
echo -e "string"

with
Code:
printf "string"

--edit--
annotated:
Code:
80:    if [ ! "x$curl" == "x" ];then                                                             # single =
118:    if [ $2 ] && [ "$status" == "0" ];then                                                   # single =
156:if [ "x$url" == "x" -o "x$token" == "x" ]                                                    # single =
162:if [[ `which curl` =~ "/curl" ]]                                                             # use case statement test for */curl* or use type statement instead of which
166:if [[ `which wget` =~ "/wget" ]]                                                             # use case statement test for */wget* or use type statement instead of which
171:if [[ ! $curl && ! $wget ]];                                                                 # if [ ! $curl ] && [ ! $wget ]
180:    if [ "$host" == "" ] || [ "$State" == "" ]; then                                         # single =
200:        arr=($line)                                                                          # set -- $line
201:        if [ ${#arr[@]} != 0 ];then                                                          # if [ $# != 0 ]; then
202:            if [[ ${#arr[@]} < 3 ]] || [[ ${#arr[@]} > 4 ]];then                             # if [ $# -lt 3 ] || [ $# -gt 4 ]
203:                echo "ERROR: STDIN must be either 3 or 4 fields long, I found "${#arr[@]}    # printf "%s\n" "ERROR ... I found $#"
205:                if [ ${#arr[@]} == 4 ]; then                                                 # if [ $# -eq 4 ]; then
207:                    <servicename>${arr[1]}</servicename>                                     # <servicename>${2}</servicename>
208:                    <hostname>${arr[0]}</hostname>                                           # <hostname>${1}</hostname>      
209:                    <state>${arr[2]}</state>                                                 # <state>${3}</state>
210:                    <output>${arr[3]}</output>"                                              # etc...
213:                    <hostname>${arr[0]}</hostname>
214:                    <state>${arr[1]}</state>
215:                    <output>${arr[2]}</output>"
219:                checkcount=$[checkcount+1]                                                   # checkcount=$((checkcount+1))


Last edited by Scrutinizer; 02-25-2015 at 03:29 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert bash to sh URGENT :(

Hi, I have to write a program to compare 2 files for copying. the program is ran on Solaris 5.8 like this: script.sh file1.txt file2.txt I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I... (2 Replies)
Discussion started by: Chris Jones
2 Replies

2. Shell Programming and Scripting

Why generate "ash and bash" different output for same bash script?

Hi, For my bash script, terminal with bash is generate an OK output and program works right. already, terminal with ash have "line 48: syntax error: Bad substitution" output and program don't work. :confused: (0 Replies)
Discussion started by: s. murat
0 Replies

3. Shell Programming and Scripting

***convert from perl to bash***

can any body translate the follwing script into one that works in bash? #!/usr/bin/perl # classify_books.pl my $csv_file = shift; my %categories = ( 'childrens' => 'childrens_books.txt', 'horror' => 'horror_books.txt', 'sports ' =>... (3 Replies)
Discussion started by: ferrycorsten73
3 Replies

4. UNIX for Dummies Questions & Answers

Differences in BASH and ASH shells regarding if command?

Guys I now have a script that's working in a BASH environment, however one line doesn't appear to be working on an embedded device that has a busybox therefore ASH shell. I've googled but there's very little I can find regarding the ASH shell. In BASH the following line works... if ] ;... (6 Replies)
Discussion started by: Bashingaway
6 Replies

5. Programming

Convert Bash script to C

dear all, i need your advice for convert bash shell to C programming INDEX=/zpool1/NFS/INDEX/${1} SCRIPT=/zpool1/NFS/script/${1} LIST=SAMPLE cd ${SCRIPT} for i in `cat ${LIST}` do GETDATE=`echo ${i}|awk '{print substr($1,9,8)}'` /usr/xpg4/bin/awk -F ":" '{close(f);f=$4}{print >>... (2 Replies)
Discussion started by: zvtral
2 Replies

6. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

7. Ubuntu

Bash to Ash, errors and adjustments

I wrote Bash script and now I want to convert it to Ash. One headache is this function: do_adduser() { setaddprompt _arr_add=("Add manually" "Add via TXT" "return to main menu" "exit program") select add_action in "${_arr_add}" do case "$REPLY" in 1)... (7 Replies)
Discussion started by: fzivkovi
7 Replies

8. Ubuntu

Bash to ash port, character-matching problem

I'm trying to convert this working bash script into an Ash script, read -p "Username:" _username if ! ]]; then echo "Valid" else echo "INVALID" fi However, Ash does not recognize the "=~" character. How can I do this? Also, is there a good reference guide, so I... (5 Replies)
Discussion started by: fzivkovi
5 Replies

9. Shell Programming and Scripting

Bash to convert to m-d-yyyy

I am using bash that when run downloads a file a verifies that there is data in it. What I am not able to do is have a user enter a date in any format they wish and have it converted to m-d-yyyy. Thank you :). Bash printf " Welcome to NGS analysis, checking for new files and creating a... (2 Replies)
Discussion started by: cmccabe
2 Replies
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy