Reassign value to a string variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reassign value to a string variable
# 1  
Old 02-08-2010
Reassign value to a string variable

hi to all,

i have a string variable that i want to reassign a new value in it through a script and i am having some trouble.
i write the following if statement:

Code:
if [ $checkupd!="lastupdate" ]
then
$checkupd="lastupdate = "
fi

in this statement i check if the variable checkupd contains the word "lastupdate". if it doesnt contain this word then i want to assign it as a value of this variable. when i run it i get the following error:
Code:
=lastupdate = : not found

do i have to assign it with different way?

thank you for your time
[/SIZE][/SIZE]

Last edited by pludi; 02-08-2010 at 10:43 AM.. Reason: code tags, please...
# 2  
Old 02-08-2010
Quote:
Originally Posted by omonoiatis9
hi to all,

i have a string variable that i want to reassign a new value in it through a script and i am having some trouble.
i write the following if statement:

Code:
if [ $checkupd!="lastupdate" ]
then
$checkupd="lastupdate = "
fi

Should be:

Code:
if [ "$checkupd" != "lastupdate" ]
then
  checkupd="lastupdate = "
fi

You should have a read of:

BASH Programming - Introduction HOW-TO
# 3  
Old 02-09-2010
thank you for your help!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if string variable is a subset of another string variable

Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument. echo "FILE PROPERTY: $fileprops" echo "PARAMETER3: $1" if ; then echo "We are Good. $line FILE is found to be INTACT !! " else echo... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. UNIX for Beginners Questions & Answers

Grep a sub-string from a string stored in a variable.

For example: I am grepping "Hello" from a file and there are 10 matches. So all ten lines with match will get stored into a variable($match). Now I want to ignore those lines which have "Hi" present in that. Currently I tried this: match = grep "Hello" file | grep -v "Hi" file But that's not... (2 Replies)
Discussion started by: pavan
2 Replies

3. Shell Programming and Scripting

[Solved] reassign value to variable

Hi, Please let me know how to reassign value to a variable.The calling script is passing parameter as HAT_DIV but I like to pass HAT DIV ( two words) to DIV parameter.These are .ksh scripts. # access to target - (user passwd sid) must be provided. USER=$1; ... (5 Replies)
Discussion started by: sandy162
5 Replies

4. Solaris

reassign zfs pool lun

I have a branded zone txdjintra that utilizes a pool named Pool_djintra that is no longer required. There is a 150 Gig Lun assigned to the pool that I need to reassign to another branded zone txpsrsrv07 with a pool named Pool_txpsrsrv07 on the same sun blade. What is the process to do this? ... (0 Replies)
Discussion started by: jeffsr
0 Replies

5. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. Shell Programming and Scripting

parsing a string into variable

I know solution to this but I was wondering if its easier than what i think I have to pass 20 parameters to a script, which of course is not working so I parsed $3 to be a pipe deliminated string for instance below a.ksh One Two Compa|Compb|Compc|compd|............. Now i have to read... (5 Replies)
Discussion started by: Anubhav
5 Replies
Login or Register to Ask a Question