Read variable inputs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read variable inputs
# 1  
Old 04-02-2013
MySQL Read variable inputs

I am trying to make an interactive script. Only problem my inputs are not read and correctly channeled.

Please help:



Here is my code

Code:
#!/bin/sh
PATHSCRIPT=/home/pp/tmp

#if [ -z "$1" ]; then
# echo "Syntax : $0 input off lat sample"
#  exit 1
#  fi
echo "Choice of Graph"

echo "1 -- Type one graph 2 -- Type two graph 3 -- type three graph"


 read num

if [[$num -eq 2]]; then

#echo " Enter arguments seperated with space: input off lat sample"
echo "Syntax : $0 input off lat sample"
#read $input $off $lat $sample
if [ $# -lt 2 ];
then
echo -e $HELP
exit 1
else
INPUT=$1
shift
OFF=$1
shift
LAT=$1
shift
SAMPLE=$1
shift
fi

else

if [[num==1]]; then
echo " Enter arguments seperated with space: input off lat sample"
#read $input $off $lat $sample

else

echo " Enter arguments seperated with space: input off lat sample"
#read $input $off $lat $sample
fi

fi

I keep receiving this error:

Choice of Graph
"1 -- Type one graph 2 -- Type two graph 3 -- type three graph"
+ read num
2
+ [[2 -eq 2]]
./mastergraph_options.sh: 1: [[2: not found
+ [[num==1]]
./mastergraph_options.sh: 1: [[num==1]]: not found
+ echo Enter input off lat sample
Enter arguments seperated with space: input off lat sample


I cannot get past this place.
Please help me read the
--Choice 1,2 or 3
-- channel it to the right format of files to be entered
Smilie
# 2  
Old 04-02-2013
Code:
if [[ $num -eq 2 ]]; then

space should be there in brackets
# 3  
Old 04-04-2013
i tried that, but got this error:

Code:
Choice of Graph
1 -- Type one graph 2 -- Type two graph 3 -- type three graph
+ read num
2
+ [[ 2 -eq 2 ]]
./mastergraph_options.sh: 1: [[: not found
+ [[ 2 -eq 1 ]]
./mastergraph_options.sh: 1: [[: not found
+ echo  Enter input off lat sample 
 Enter input off lat sample

# 4  
Old 04-04-2013
Try [ ] instead of [[ ]]. Some extremely old shells don't have the new [[ ]] brackets yet.
# 5  
Old 04-04-2013
Perfect..
it works...1st half

now the second half is problematic.

I cannot read the input values.

Help pleaseee
# 6  
Old 04-04-2013
You have read $VAR1 $VAR2 $VAR3

This is incorrect, you must do read VAR1 VAR2 VAR3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output read variable

Hi all, how read varaible and ouput in colum, e.g. $ echo $VAR1 opc op odi games gopher vcsa abrt I like $ echo $VAR1 opc op odi games gopher vcsa abrt (3 Replies)
Discussion started by: aav1307
3 Replies

2. Shell Programming and Scripting

how to read a variable?

i want to ask how can i read a variable? like for i in 1 2 3 do cat file${1} | while read something do if echo " file name: file${i}" >>temp else echo ", file${i}" >>temp done done it is not working, can i do something like that? actually i want the output below file name:... (4 Replies)
Discussion started by: mingming88
4 Replies

3. Shell Programming and Scripting

Can I use read to read content of a variable

Can I use the read command to read the contents of a variable? I'm trying by using the following code and getting nothing back. I'm in a Linux environment. #!/bin/ksh IFS=~ VAR1=1~2~3~4 echo $VAR1 | read a b c d print "$a $b $c $d" (9 Replies)
Discussion started by: nmalencia
9 Replies

4. Programming

Using ioctl to read mice inputs

I was wondering if its possible to read mouse inputs using ioctl functions somehow ? If it is not too much of trouble can anyone write or even direct me to sample code of ioctl reading someother HID. (2 Replies)
Discussion started by: maverick_
2 Replies

5. Shell Programming and Scripting

How to read inputs from a file

Hello; Please I need to read inputs from a file change 1 or 2 things the output to another file. (1 Reply)
Discussion started by: jimoney
1 Replies

6. Shell Programming and Scripting

read several inputs and if none input set to 9999

need a script that goes something like this #!/usr/bin/bash echo "input up to TEN values, separated by spaces" read vari1 vari2 vari3 vari4 vari5 vari6 vari7 vari8 vari9 vari10 #set null variables to 9999 (somehow?) #now echo all variables echo $vari1 $vari2 $vari3 $vari4 $vari5 $vari6... (1 Reply)
Discussion started by: ajp7701
1 Replies

7. Programming

Handling variable inputs

Hi, Is there any way to handle variable inputs. If an application handles more than one input how to print the input values. Example : ./a.out 1 "hi" 3 ./a.out 1 ./a.out 1 3 4 "hello" output should be: 1 hi 3 1 (1 Reply)
Discussion started by: yhacks
1 Replies

8. Shell Programming and Scripting

read n number of inputs

Hello, I think its a sinple query but somehow i m stucked up here... I am trying to enter n number of inputs from the user and write them in an input file ie row wise... I tried standard commands like $echo "enter the inputs for the file" $read var1 var2 var3 var4 test1 test2... (14 Replies)
Discussion started by: er_aparna
14 Replies

9. UNIX for Dummies Questions & Answers

Cant read in variable on first try

Hi, My problem is : echo Division read vDivision variable1=`cut -c **something****' echo Do you want to proceed ? read ans I cant seem to read in ans on the first try and have to repeatedly enter the return key. If i remove the ` ` statement its ok but i need that line for... (1 Reply)
Discussion started by: normie
1 Replies

10. UNIX for Advanced & Expert Users

Cannot read in variable using read on first try

Hi, My problem is : echo Division read vDivision variable1=`cut -c **something****' echo Do you want to proceed ? read ans I cant seem to read in ans on the first try and have to repeatedly enter the return key. If i remove the ` ` statement its ok but i need that line for... (1 Reply)
Discussion started by: normie
1 Replies
Login or Register to Ask a Question