Working with Script variables; seems like this should work...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Working with Script variables; seems like this should work...
# 1  
Old 07-27-2007
Working with Script variables; seems like this should work...

The following seems quite basic but does not seem to work. Anybody know why?

$ g=1
$ echo $g
1
$ echo abc$g
abc1
$ abc$g=hello
ksh: abc1=hello: not found
$ echo $abc1
ksh: abc1: parameter not set

It works when I specify the full variable name
$ abc1=hello
$ echo $abc1
hello

Thanks.
# 2  
Old 07-27-2007
try
Code:
eval abc$g=hello

# 3  
Old 07-27-2007
That worked

That worked. Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Bash] passing variables to executable doesn't work

Bash version 4.4.20 / Ubuntu 16.0.4 Hello, I tried to write a script that gathers some data and passes them to an executable. The executed application answers with an error. The echo output in the script returns correct values. If I copy/paste the last echo command, it get's executed... (2 Replies)
Discussion started by: sushi2k7
2 Replies

2. Shell Programming and Scripting

Problem getting sed to work with variables

Hello, I am processing text files looking for a string and replacing the first occurrence of the string with something else. For the text,id Name 1 methyl-(2-methylpropoxy)-oxoammonium 2 N-amino-N-(methylamino)-2-nitrosoethanamine 3 3-methoxy-3-methyloxazolidin-3-ium... (12 Replies)
Discussion started by: LMHmedchem
12 Replies

3. Shell Programming and Scripting

Variables not working

Hello, I have a (basic I guess) problem with bash scripting. In the command line, this piece of code returns nothing (a blank line), and if I'm not worng it should return 3. set VAR = "3" echo $VAR if I do this (also in command line), a zero is returned: set VAR = 3 printf "%d"... (4 Replies)
Discussion started by: jlseminara
4 Replies

4. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

5. Shell Programming and Scripting

Script that "should work" it's not working.

Hi, this is my script: #!/bin/bash trabajo=$1 numero=`jobs | grep -n $trabajo | cut -d':' -f1` echo $trabajo echo $numero kill %$numero wait For some reason, numero=`jobs | grep -n $trabajo | cut -d':' -f1` that line wont save in numero the number I am looking for BUT if I write it... (7 Replies)
Discussion started by: lamachejo
7 Replies

6. Shell Programming and Scripting

reading external variables does not work

... declare vINIFILE vINIFILE=$1 ... echo "The name of the File is $vINIFILE" >>mail_tmp echo "" >> mail_tmp.$$ ... grep RUNJOB=0 $vINIFILE >>tmp_filter ... So the strange is in echo-statement I get the correct output for $vINIFILE wrtitten into the file mail_tmp. But the... (2 Replies)
Discussion started by: ABE2202
2 Replies

7. Shell Programming and Scripting

cd command doesn't work through variables

Hi.... cd command is not working when dual string drive/volume name is passed to cd through variables....... For Ex.... y=/Volumes/Backup\ vipin/ cd $y the above command gives error....... anyone with a genuine solution ? (16 Replies)
Discussion started by: vipinchauhan222
16 Replies

8. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

9. UNIX for Advanced & Expert Users

variables don't work for inline "su" script

My first post here... I cannot get variables to work when using inline KSH commands on a "su" command. I have a KSH script, below, that produces my problem: #!/usr/bin/ksh su <user_id> <<-END export FLD1=`echo $PWD` pwd echo $FLD1 echo TEST echo $PWD END The script will prompt me... (3 Replies)
Discussion started by: joekreif
3 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question