bash integer & string issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash integer & string issue
# 1  
Old 11-25-2010
bash integer & string issue

Hi guys,

I need for the bash code below a little bit help: cat script.sh

Code:
#!/bin/bash
5_MYVALUE="test"
echo "$5_MYVALUE"


If I try to run the script, got follow failure:

Code:
./script.sh
./script.sh: line 4: 5_MYVALUE=test: command not found
_MYVALUE

My questions are how can I set a string to show the value test without to change the integer 5 or the special char "_" ?

for example the output should be:

Code:
./script.sh
test

Thx
Research3
# 2  
Old 11-25-2010
give a try as..
Code:
echo "${5_MYVALUE}"

# 3  
Old 11-25-2010
Unfortunately the same result:

Code:
#!/bin/bash
5_MYVALUE="test"
echo "$5_MYVALUE"
echo "${5_MYVALUE}"

The output:

Code:
./script.sh
./script.sh: line 4: 5_MYVALUE=test: command not found
_MYVALUE
./script.sh: line 6: ${5_MYVALUE}: bad substitution

# 4  
Old 11-25-2010
hmm my mistake.. shell variables cannot begin with numerics. Reference: here
# 5  
Old 11-25-2010
I will create now a new workaround for this task!
Thanks michaelrozar17 for you feedback!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String to integer

I am on HP-UX using ksh in the script. MaxSal=`sqlplus -silent /nolog <<EOF connect / as sysdba whenever sqlerror exit sql.sqlcode set pagesize 0 feedback off verify off heading off echo off select max(sal) from emp1; select max(sal) from emp2; select max(sal) from emp3; exit; EOF`... (3 Replies)
Discussion started by: bang_dba
3 Replies

2. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

3. Shell Programming and Scripting

Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008)

Hi, I have the following requirement. There will be following text/line in a file (eg: search-build.txt) PRODUCT_VERSION="V:01.002.007.Build1234" I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get... (4 Replies)
Discussion started by: drwatson_droid
4 Replies

4. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

5. UNIX for Dummies Questions & Answers

integer to string

Hi all, is there an easy way to convert integer to string in bash? I have numbers like 1, 2, ..., 112, ... and I would like to get 001 002 003 004 ... Thank you, Sarah (4 Replies)
Discussion started by: f_o_555
4 Replies

6. Shell Programming and Scripting

bash version or string issue

Hi all, I'm not sure but I guess, that is a bash version issue. The script working fine on "GNU bash, version 3.2.25(1)-release Ubuntu". #!/bin/bash while IFS=">" read a id val do if ] then VAL=${id%<*}; ID=${id#*</} echo $VAL echo $ID sed... (5 Replies)
Discussion started by: research3
5 Replies

7. Shell Programming and Scripting

how to compare string & integer in unix

Hi All, i am doung sup up of amount column in my file. tot_val=`awk '{a+=$0}END{printf "%.5f\n",a}' amount` then i have a checksum in footer. chk_sum=`tail -1 $FILE_NAME | cut -d~ -f7 | cut -c2-` but the problem is while executing 1st command i am getting : 27720.75000 & while... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

8. Shell Programming and Scripting

Non-integer calculations in bash

I'm new at scripting but I thought I was getting pretty good at it. I've hit a snag. I try to use expr to compute a fraction say: expr 3 / 4, and I'm getting zero. I guess it's just truncating to the integer, in this case 0, but I need the decimal 0.75. What can I do to compute this value in... (2 Replies)
Discussion started by: jeriryan87
2 Replies

9. Shell Programming and Scripting

Checking if string contains integer

G'day guys, first post so be gentle. I need help with some code to work out if a variable (string) contains any integers. The valid variable (string) must contain only letters. Also need to be able to work out if a variable contains only integers. Any help greatly appreciated. (7 Replies)
Discussion started by: haz
7 Replies

10. Programming

Integer to String

Which function should I use to convert an Integer to a String or Char format ? Thanx (2 Replies)
Discussion started by: psilva
2 Replies
Login or Register to Ask a Question