getting rid of $ when entered at the command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting rid of $ when entered at the command line
# 1  
Old 04-04-2003
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  
Old 04-04-2003
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  
Old 04-04-2003
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

2. Shell Programming and Scripting

Perl : accept multiple user entered command line arguemnts

I am trying to create a script that will accept multi input from the user (really just me), then execute those command on a remote device. My question is if the I enter "No" at the confirmation point "Are these statements correct y or n ?", what is the best way to go back and start over ? I... (3 Replies)
Discussion started by: popeye
3 Replies

3. Shell Programming and Scripting

Trying to get rid of a duplicate output line...

Hi folks, I'm trying to work on a script that will grab a router interface report and generate the numbers of "in use" and "un-used" ports per device. Right now, I've got a cut down of the report as follows: sing /usr/apps/siteName/etc/DCAFT-9K.cmds for send text Connecting using... (11 Replies)
Discussion started by: Marc G
11 Replies

4. Shell Programming and Scripting

How to loop through array who's name is entered in command line?

Say I have a ksh program called test.ksh which has several defined arrays inside it such as array1,array2,array3...These arrays contain strings. I also have a method in the program: for x in $1 do ....(#do something) done So, when the user enteres: ./test.ksh array1, I want to... (3 Replies)
Discussion started by: mrskittles99
3 Replies

5. Shell Programming and Scripting

Delete empty files from a directory entered in command prompt

My code to "Delete empty files from a directory entered in command promt" #/bin/sh echo "Enter directory" read gh for file in `ls $gh` do # to get the size of file a=$( ls -l file | awk ' {print $7} '); echo $a if then echo "removing file " rm file fi done (6 Replies)
Discussion started by: adirajup
6 Replies

6. Shell Programming and Scripting

Get rid of the 7th character of each line if this is a space

I have a text file like this ... B 16 1.340E+05 A 18 3.083E+02 Wu123 1.365E+02 ... I would like to get rid of the 7th character of each line if this is a space character. Thank you, Sarah (5 Replies)
Discussion started by: f_o_555
5 Replies

7. Shell Programming and Scripting

Repeat last entered command ?

Hi, how to do that ? I mean only print it but not execute. I'm using putty to interact with ksh. (in windows cmd up arrow does the job) thanks vilius (5 Replies)
Discussion started by: vilius
5 Replies

8. UNIX for Dummies Questions & Answers

Append 0 for single digit entered from command line

I have a script like this-- #!/bin/ksh echo "To pad a 0 before digits from 1-9" for i in $* do echo $i | sed 's//'0'/g' done I run this script as ksh name 1 2 23 34 The output should be 01 02 23 34 Help me in modifying this script. Thanks Namish (2 Replies)
Discussion started by: namishtiwari
2 Replies

9. Shell Programming and Scripting

How to get rid of last line

I have to process a data file in Ab Initio. This data file is pipe delimited. BUt the file may have a Disclaimer line at the end. So before picking it for processing, I need to check if this line is there I need to remove it. ANy suggestions. Thanks Shalu (1 Reply)
Discussion started by: shalua
1 Replies

10. Shell Programming and Scripting

how to get rid of blank line in a flat text file

Hi, I have a flat text file which contains blank line between each text line. Is there any command to get rid of it? Thanks for your help (11 Replies)
Discussion started by: xfang
11 Replies
Login or Register to Ask a Question