The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace command in one line using one command vasikaran UNIX for Dummies Questions & Answers 10 08-20-2008 11:40 AM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 07:06 PM
i want to know entered string ends with .jar naree Shell Programming and Scripting 3 03-08-2008 07:24 AM
Repeat last entered command ? vilius Shell Programming and Scripting 5 09-25-2007 07:15 AM
Append 0 for single digit entered from command line namishtiwari UNIX for Dummies Questions & Answers 2 08-24-2007 06:01 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2003
bashirpopal bashirpopal is offline
Registered User
  
 

Join Date: Jul 2002
Location: Canada
Posts: 8
Question getting rid of $ when entered at the command line

Hi everyone,
Can someone possibly help me with this problem I am having please.
I wrote a Korn shell script to manipulate currency amounts in a way that a person could use this script to determine the minimum number of coins required to make a certain amount.

for example when entered on the command line:
$coins 5.67
the script will break the amount down to the minimum number of coins (toonies, loonies, quarters, dimes, nickles and pennies) totaling 5.67.
the problem is that I can't get rid of $ if entered before the amount on the command line, cos' the shell takes it as the command line argument.
I tried using sed to omit $ from the amount, so when I enter
$coins $5.67
the out put of sed is:
67
not 5.67

Your help will be greatly appreciated.
Bashir
  #2 (permalink)  
Old 04-04-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Is just using single quotes an option? Or a backslash, but that's uglier and probably harder for a user to remember...

> coins '$5.67'
> coins \$5.67

Last edited by oombera; 04-04-2003 at 11:28 AM..
  #3 (permalink)  
Old 04-04-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,124
The problem is that the interactive shell that is accepting the command line will treat $ specially. This happens before it even locates your coins script. Quoting the $ is an option.

Another option is to prompt the user for input and then read it yourself. And to strip off a dollar sign, you don't need sed when you're using ksh...

#! /usr/bin/ksh

print -n "Enter amount - "
read amt
print amt is $amt
amt=${amt#$}
print amt is $amt
exit
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0