Input and value problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Input and value problem
# 1  
Old 07-22-2010
Input and value problem

Hi, I need to convert given cents to dollars so I have a script with this this:

Code:
A=$(echo "$1*0.01" | bc)
echo $A

B=$(echo "$2*0.01" | bc)
echo $B

C=$(echo "$3*0.01" | bc)
echo $C

D=$(echo "$4*0.01" | bc)
echo $D

E=$(echo "$5*0.01" | bc)
echo $E

F=$(echo "$6*0.01" | bc)
echo $F

G=$(echo "$7*0.01" | bc)
echo $G

H=$(echo "$8*0.01" | bc)
echo $H

I=$(echo "$9*0.01" | bc)
echo $I

J=$(echo "$10*0.01" | bc)
echo $J

K=$(echo "$11*0.01" | bc)
echo $K

L=$(echo "$12*0.01" | bc)
echo $L

When I run that I get:

Code:
[root@Blah Script]# ./test 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234
12.34
12.34
12.34
12.34
12.34
12.34
12.34
12.34
12.34
123.40
123.41
123.42

Notice that it works just fine except for the las three ($10, $11, $12).
Any ideas on how to make it work?

Thanks!
# 2  
Old 07-22-2010

Positional parameters greater than 9 must be enclosed in braces:
Code:
printf "%s\n" "${10}" "${11}" "${12}"

Otherwise, $10 is interpreted as ${1}0
# 3  
Old 07-22-2010
Quote:
Originally Posted by cfajohnson

Positional parameters greater than 9 must be enclosed in braces:
Code:
printf "%s\n" "${10}" "${11}" "${12}"

Otherwise, $10 is interpreted as ${1}0
Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python problem with input

Hello everyone, I have just started python, and there is something that escapes me. I don't understand why my little script doesn't work. When I do, it work: my_string = "bonjour" if len(my_string) < "6": print(my_string + " < 6") else: print(my_string + " > 6") ... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

2. Shell Programming and Scripting

Problem in reading the input value

echo "Enter the Value : " read value sed '1s:\(.\{6\}\)\(.\{4\}\):\1'$value':' flextran$RUN_DATE-completed.txt > temp.txt mv temp.txt flextran$RUN_DATE-completed.txt on the run time after entering the input value it waits for keystroke and the values is not input to the function The output... (4 Replies)
Discussion started by: rammm
4 Replies

3. Shell Programming and Scripting

Case Contruct Problem user input

This is supposed to be a simple bank script. Whenever I try the case construct options it wont work for the deposit option after typing the amount it just goes straight back into the menu, same with withdrawal option. Option 3 which should just display the balance amount doesn't echo anything. The... (2 Replies)
Discussion started by: jcnewton13
2 Replies

4. Homework & Coursework Questions

Problem parsing input with awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I want add a line.For example:- 123456 1 1 0 1 1 0 1 0 0 0 1 5 8 0 12 10 25 its answer... (4 Replies)
Discussion started by: Arsh10
4 Replies

5. Shell Programming and Scripting

Problem with input parameters

Hi I wrote a script which lists the content of a given directory. I have just one problem. If you give 2 or more parameters, then it gives a strange error. After that error, it gives also an error from my script, but normally it shouldn't give that error. Here's my script.You can test it. ... (3 Replies)
Discussion started by: hss
3 Replies

6. Shell Programming and Scripting

[SH] Problem reading input in script

Alright, so the goal of my script is to read text from standard input and store it into a file using the ex-editor: so far i've got this, but it doesn't work. #!/bin/s read text ex $1 >> HERE text HERE I don't get any errors either, so i don't know what i'm doing wrong. (7 Replies)
Discussion started by: Bertieboy7
7 Replies

7. Shell Programming and Scripting

Problem with Input parameters

Hi, I am facing a weird problem with input parameters. Please find more details about my problem below: a) I am executing a korn shellscript with 11 input parameters from "Appworx" tool (it's a scheduling tool) and immediately displaying those 11 parameter values in unixscript and noticed... (4 Replies)
Discussion started by: npk2210
4 Replies

8. Shell Programming and Scripting

Problem while taking input from User

Hi All, I am facing a problem while taking input from user in Shell Script. Basically , I want to read a file line by line. And I want to remove certain lines of that file.But before removing those lines , I need to ask the user whether user wants to remove the lines. If user inputs "Yes" , the... (3 Replies)
Discussion started by: swapnil.nawale
3 Replies

9. Shell Programming and Scripting

Problem taking input from file with for loop

I am trying to take input from a file and direct it into a bash script. This script is meant to be a foreach loop. I would like the script to process each item in the list one by one and direct the output to a file. # cat 1loop #!/bin/bash # this 2>&1 to redirect STDERR & STDOUT to file... (4 Replies)
Discussion started by: bash_in_my_head
4 Replies

10. Shell Programming and Scripting

Problem with ^M in input file

Greetings to all, I have this problem comparing two file and extract the output from it. "input.txt" file(Extracted from excel): ABC ABB ABA "compare.txt" file(Extracted from excel): ABA 1 ABB 2 ABC 3 ABD 4 ABE 5 ABF 6 ABG 7 I would like to get output of ABC 3 (2 Replies)
Discussion started by: noelcantona
2 Replies
Login or Register to Ask a Question