LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-09-2011, 12:59 AM   #1
dan-e
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: 0
Convert ksh script into bsh script trouble


Hi all,

I found a handy script that I want to be able to convert to run on bsh. The script was written for ksh which I do not have and cannot install. The script errors out on the "set -A" part, I'm wondering if anyone here has a workaround to get this baby going?

(FYI: The script is supposed to print out the first n unused UIDs from /etc/passwd)

Code:
#! /bin/bsh

# newuids --- print one or more unused uids
#
# usage:
#       newuids [-c N]
#       -c N            print N unused uids

PASSWD=${PASSWD:-/etc/passwd}
TMPFILE=/tmp/uidlist$$

trap 'rm -f $TMPFILE' EXIT HUP TERM     # clean up on exit or signal

count=1         # how many uids to print

# parse arguments, let ksh issue diagnostics
# and exit if need be
while getopts "c#" opt
do
        case $opt in
        c)      count=$OPTARG ;;
        esac
done

awk -F: '{ print $3 }' $PASSWD |  # generate list of uids
sort -n -u > $TMPFILE             # sort numerically, remove duplicates

set -A uidlist $(< $TMPFILE)      # save in indexed array

totalids=${#uidlist[*]}           # total number of uids

# loop over ids, finding non-contiguous ones
for ((i = 2; i <= totalids; i++))
do
        if (( uidlist[i-1] + 1 != uidlist[i] ))
        then
                for ((j = uidlist[i-1] + 1; j < uidlist[i]; j++))
                do
                        print $j
                        if (( --count == 0 ))
                        then
                                break 2
                        fi
                done
        fi
done
 
Old 05-09-2011, 01:11 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,247

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
Which distro is this? ksh should be avail in most.
Anyway, I think you mean bash not bsh??

http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert python script to shell script investmentbnker75 Programming 13 09-05-2010 01:38 AM
Can somebody help me with a ksh script? twentymil AIX 7 01-21-2004 09:55 AM
KSH script AquamaN Programming 2 12-08-2003 11:34 AM
Bsh Script ( Email ) joseph Linux - Networking 3 10-29-2003 10:36 PM


All times are GMT -5. The time now is 08:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration