Register
It is currently Thu Sep 18, 2014 5:39 am

two scripts please help!


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Apr 16, 2010 4:40 pm   

Joined: Fri Apr 16, 2010 4:36 pm
Posts: 1
Hi everyone,

First off, i'm looking for a tutor. I am not understanding bash scripting at all and would be willing to pay someone for help. Please e-mail me with contact info if interested asap to moos928@hotmail.com Anyways, here are the two scripts i need help with. Any help would be much appreciated!!! Thanks!!! Btw, using VI editor on these.


2. Create a script named decimal.bash to output a decimal number when a
binary number is passed in as an argument. The script should check
to see if the correct number of arguments have been passed into the
script. It should display a usage message if the incorrect number
of arguments are entered.


3. Copy the file /home/share/passwd.dat to your scripts directory. Create
a script named passwd.bash that will display the contents of the
passwd.dat file in the following format.

John Smith's password is JS1234
Sue Doe's password is SD2223

The passwd.dat file name should be passed in as an argument. The script
should check to see if the correct number of arguments have been passed
into the script. It should display a usage message if the incorrect
number of arguments are entered. Where the JS are initials and 1234 are
the last for digits of the social security number.


Top
 Profile  
 PostPosted: Mon Apr 19, 2010 11:54 pm   

Joined: Wed Apr 14, 2010 10:23 am
Posts: 17
First one, as far as I could make sense out of the question:
Code:
#!/bin/bash

print_help() {
  cat <<HELP

Usage:
$0    BINARY                binary number to print in decimal
HELP
}

if [[ $# -ne 1 ]]; then
  printf "Error: wrong number of arguments\n" >&2
  print_help >&2
  exit 1
fi

if [[ $1 = *[^01]* ]]; then
  printf "Error: '$1' is not a valid binary number\n" >&2
  print_help >&2
  exit 1
fi

printf "%s\n" "$((2#$1))"


Second one: You forgot to mention the contents of that file. For the sanity checks, do it similar like the above (number of arguments), plus an -r test on the given filename. I can't tell you how to parse a file I don't know the contents of.


And: Homework is meant to be done by yourself.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP