Results 1 to 3 of 3
I don't really know much about programming/scripting that much. I had one programming class once. I am trying to get the following to work, but it only works with numerical ...
- 05-05-2010 #1
Double variable -- I think
I don't really know much about programming/scripting that much. I had one programming class once. I am trying to get the following to work, but it only works with numerical numbers, and fails with text. How can I get the text portion to work?:
The above returns the following:PHP Code:#!/bin/bash
LARGE_FILE_MAX_SIZE=5
LARGE_FILE_TYPE=GB
convert_data (){
CONVERT_TYPE=$((${1}_FILE_TYPE))
CONVERT_TOTAL=$((${1}_FILE_MAX_SIZE))
echo CONVERT_TYPE: $CONVERT_TYPE
echo CONVERT_TOTAL: $CONVERT_TOTAL
}
convert_data LARGE
# ./data_gen.sh
CONVERT_TYPE: 0 <--- I need this to read GB (or whatever string is passed in)
CONVERT_TOTAL: 5
Thanks in advance for your help
BTW: I am not a student and this isn't homework. It is a script I am trying to refine that will generate large amounts of custom data for some of the testing I have to do. My current script generates the data, but I am refining it to give me more control of the size of data it will generate (this is only a small portion of the overall script)
- 05-06-2010 #2Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
Code:#!/bin/bash LARGE_FILE_MAX_SIZE=2 LARGE_FILE_TYPE=GB convert_data (){ CONVERT_TYPE=${1}_FILE_TYPE CONVERT_TOTAL=$((${1}_FILE_MAX_SIZE)) echo CONVERT_TYPE: ${!CONVERT_TYPE} echo CONVERT_TOTAL: $CONVERT_TOTAL } convert_data LARGEwill always returm 0 as the resulting variable contains a non numeric value.CONVERT_TYPE=$((${1}_FILE_TYPE))
becomes the the value "LARGE_FILE_TYPE" contained in "CONVERT_TYPE"${1}_FILE_TYPE
is bash's variable indirection. "LARGE_FILE_TYPE" is used as a variable in itself and points to it's content : GB${!CONVERT_TYPE}Last edited by nmset; 05-06-2010 at 09:22 AM.
0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-06-2010 #3
NICE! Thank you very much. I don't quite understand what you said, but I see that it works. I work with a guy that can explain what you did to me.
Thank you.


Reply With Quote