Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7163193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:51:38+00:00 2026-05-28T13:51:38+00:00

How do I rewrite this script in Korn Shell? It’s in Bash right? I’m

  • 0

How do I rewrite this script in Korn Shell? It’s in Bash right? I’m a little confused to the actual differences between all the shells… Am I on the right track to converting it to Korn Shell?

usage ()
{
     echo      "usage: ./file.sk user"
}
# test if we have two arguments on the command line
if [[ $# != 1 ]]
then
    usage
    exit
fi

# Search for user
fullname=$(cut -f1 -d: /etc/passwd | grep "$1")
if [[ $? -eq 0 ]]; then
                echo "User already found:"
                grep $1 /etc/passwd
        exit
        else
                #get numbers
                cat /etc/passwd | gawk -F: '{print $3}' | sort -n > currentuid4
                #get last number
                last=`tail -1 currentuid4`
                echo last $last
                #add +1
                newuid=`expr $last + 1`
                #print it
                echo "ADDED: $1 with UID: $newuid"
        exit
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:51:40+00:00Added an answer on May 28, 2026 at 1:51 pm

    I suggest replacing [[ … ]] by [ … ] and using -eq/-ne to make the script more portable on different shells.

    usage ()
    {
         echo      "usage: ./file.sk user"
    }
    # test if we have two arguments on the command line                                                                                                            
    if [ "$#" -ne 1 ]
    then
        usage
        exit
    fi
    
    # Search for user                                                                                                                                              
    fullname=$(cut -f1 -d: /etc/passwd | grep "$1")
    if [ "$?" -eq 0 ]; then
                    echo "User already found:"
                    grep $1 /etc/passwd
            exit
            else
                    #get numbers                                                                                                                                   
                    cat /etc/passwd | gawk -F: '{print $3}' | sort -n > currentuid4
                    #get last number                                                                                                                               
                    last=`tail -1 currentuid4`
                    echo last $last
                    #add +1                                                                                                                                        
                    newuid=`expr $last + 1`
                    #print it                                                                                                                                      
                    echo "ADDED: $1 with UID: $newuid"
            exit
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I rewrite this code to check for all characters including the swedish
I have this code I'm trying to rewrite to c# from a vbs script.
how would I rewrite this as a php script. also if anyone knows of
Any Ideas how to change remove .html in this mod-rewrite script Doesnt work if
i need help with this 2 rewrite rules: RewriteEngine On RewriteBase / # folder/script.php?A=1&B=2
How do you rewrite this in Linq? SELECT Id, Name FROM TableA WHERE TableA.Id
How to rewrite this: select tab1.id, tab2.id, tab3.id from tab1, tab2, tab3 where tab1.col1
I want to rewrite this query so that if @UserName gets passed in a
I thought I would rewrite this question (same iteration). The original was how to
how I can rewrite this: for (int i = 0; i < numberOfSpaces; i++)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.