creating a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers creating a variable
# 1  
Old 02-22-2008
creating a variable

I cannot seem to get the following script to work. I cannot seem to set the variable. What am I missing?

bin/bash
set -x

echo "2" > /tmp/number

STATUS='grep -c 2 /temp/number'

if [ "$STATUS" -eq 1 ] ; then
echo "Number 2 is found once"
else
echo "Number 2 is found more or less than one time"
fi
# 2  
Old 02-22-2008
A couple of things. First, the first line should read:
Code:
#!/bin/bash

And this line should use backticks, not single quotes:

Code:
STATUS=`grep -c 2 /temp/number`

Another problem is that you echo to /tmp/number, but then grep /temp/number.
# 3  
Old 02-22-2008
1/ At the beginning of the script the shebang should be included,
2/ you're using ' instead of ` at line 6
3/ /tmp should be used consistently, not /temp at line 6


Code:
#!/bin/bash
set -x

echo "2" > /tmp/number

STATUS=`grep -c 2 /tmp/number´

if [[ "$STATUS" -eq 1 ]] ; then
   echo "Number 2 is found once"
else
   echo "Number 2 is found more or less than one time"
fi

# 4  
Old 02-22-2008
Thank you both!!!!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a PATH variable

I am new to shell scripting and I ran into a couple lines of code which I don't completely understand: PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/entity/bin data_dir=/usr/local/entity/projectI believe data_dir to be a more conventional link to a directory. However, I am not sure what PATH... (12 Replies)
Discussion started by: Circuits
12 Replies

2. Shell Programming and Scripting

Creating an Interactive Variable

Goal: I want run a Bash script that runs some conditional if statements on a specific file path that a user defines. Question: How do I build the prompt so the script asks the user to define the file path and then use that input as a variable? I'm guessing I will use a read builtin but I'm... (3 Replies)
Discussion started by: sudo
3 Replies

3. Shell Programming and Scripting

Creating variable by for loop

i have a file 'detail' which contains cat detail 111111 222222 333333 444444 but detail may be 4 line file.6 line file or 8 line file like cat detail 111111 222222 333333 444444 555555 666666 777777 888888 so i want a declare a loop which assign the value of first line in one... (11 Replies)
Discussion started by: rakeshtomar82
11 Replies

4. UNIX for Dummies Questions & Answers

creating a new variable from existing data

Hello, I have the following data set: TRAIT DOSE 40 0.4 30 0.3 95 1.2 120 1.7 85 1.4 136 1.8 134 1.8 40 0.4 30 0.3 95 1.2 120 1.7 85 1.4 136 1.8 134 1.8 40 0.4 30 0.3 95 1.2 (2 Replies)
Discussion started by: wolf_blue
2 Replies

5. Shell Programming and Scripting

Creating a variable in remote server

Can anyone help how to create a variable in remote server using shell script. i am connecting to remote server through ssh and creating a variable and assigning the value, but nothing is displayed when i run the script Here is my script ssh hostname <<EOF a=10 echo $a EOF (1 Reply)
Discussion started by: Rahul12341984
1 Replies

6. Shell Programming and Scripting

Creating variable using awk in bash

I would like to create a variable within my bash script using awk. I'm reading in a line from an external file, then outputting to a new file in a specific format. But, it doesnt quite work as I have expected and could use some help. (A pertinent excerpt of ) the bash code is: count=1 ... (4 Replies)
Discussion started by: snoitacilppa
4 Replies

7. Shell Programming and Scripting

creating variable array name

#!/bin/ksh #export CLASSPATH=$CLASSPATH:~dialp/cso/classes:/opt/oracle/product/8.1.6/jdbc/lib/classes12.zip #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/oracle/product/8.1.6/lib DATE="`date '+%m%d%Y'`" PATH=.:$PATH export PATH town_name='123' town_name='123' town_name='345'... (1 Reply)
Discussion started by: priyanka3006
1 Replies

8. Shell Programming and Scripting

Joining two arrays and then creating a variable

Hello all... I'd like to create a variable from an array element from two arrays. In my search for answers I found this code for bash that joins two arrays and then started to work with it. I had got to work once and then foolishly without saving the code, I started to edit it for ksh and... (4 Replies)
Discussion started by: carlos25
4 Replies

9. Shell Programming and Scripting

creating array variable

Hi all, i am quite fimiliar with shell scripting but i wouldn't regard myself as a semi professional at it. I am trying to create an array variable to read in 4 lines from a file using head and tail command in a pipeline and store each line into each array. I have done the scripting in unix... (2 Replies)
Discussion started by: scriptingmani
2 Replies

10. Shell Programming and Scripting

dynamically creating a variable name

Hi ! I have the following situation - ##First variable variableA=JOB_A ##bunch of other variable JOB_A_RESTART=cleanupJobA JOB_B_RESTART=cleanupJobB JOB_C_RESTART=cleanupJobC now i need a script which would - 1. take the first variable 2. create a new variable name... (2 Replies)
Discussion started by: hsahay
2 Replies
Login or Register to Ask a Question