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 1093927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:53:55+00:00 2026-05-16T23:53:55+00:00

I am trying to use Bourne shell scripting for the first time ever, and

  • 0

I am trying to use Bourne shell scripting for the first time ever, and I cannot seem to figure out determining how to save text from a file to internal script variables. The file format is as follows:

acc.text

Jason Bourne 213.4
Alice Deweger 1
Mark Harrington 312

The current script that I have (which might be ENTIRELY incorrect as I am simply creating it in NotePad++ without using an actual shell console) is as follows:

#!/bin/sh

process_file()
{

FILE = $1;
SALARYARRAY;
NAMEARRAY;
COUNTER = 0;

while read line
   do
 $NAMEARRAY[$COUNTER] = 
    $SALARYARRAY[$COUNTER] =
 $COUNTER + 1;
 echo $NAMEARRAY[$COUNTER]:$SALARYARRAY[$COUNTER];
done < "$FILE"

order_Map 
}

# Function is not complete as of now, will later order SALARYARRAY in descending order
order_Map()
{
i = 0;
for i in $COUNTER
 do
   if ($SALARYARRAY[
 done

}

##
# Main Script Body
#
# Takes a filename input by user, passes to process_file()
##

PROGRAMTITLE = "Account Processing Shell Script (APS)"
FILENAME = "acc.$$"


echo $PROGRAMTITLE

 echo Please specify filename for processing
 read $FILENAME

 while(! -f $FILE  ||  ! -r $FILE)
   do
  echo Error while attempting to write to file. Please specify file for processing:
  read $FILENAME
   done


echo Processing the file... 
process_file $FILENAME 
  • 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-16T23:53:56+00:00Added an answer on May 16, 2026 at 11:53 pm

    Given the file format you specified, each record has three fields first last and amount, then:

    i=0
    while read fistname lastname amount; do
        NAMEARRAY[$i]="$firstname $lastname"
        SALARYARRAY[$i]=$amount
        i = `expr $i + 1`
    done < "$FILE"
    

    The shell read built-in, automatically splits input. See the variable IFS in the man page for sh(1). If you have data after the amount field, and you wish to ignore it, just create another variable after amount; but don’t use it. It will collect everything after the 1st 3 fields into the extra variable.

    You specified Bourne shell, so I used some pretty antiquated stuff:

    i=`expr $x + 1`
    

    is usually written

    let $((i++))   # ksh, bash (POSIX, Solaris, Linux)
    

    On modern systems, /bin/sh is usually ksh or something pretty compatible. You can probably use let $((i++))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use this sql statement. The first 2 parts work fine, I am
Im trying to create a bourne shell script that will take 0 or more
I'm trying use epoch time dates in my series data. The array looks like
I'm trying use a UIScrollview inclined 350 degrees, the first thing I thought was
I have been trying use zenity with standard re-direction in a shell script, something
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The

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.