Find the answer to your Linux question:
Results 1 to 2 of 2
I have the following function, and it appears to set the var correctly, but then tries and executes the line as a command. Anyone know how to keep it from ...
  1. #1
    Just Joined! jdh239's Avatar
    Join Date
    Sep 2006
    Posts
    55

    [SOLVED] Setting var returns command not found

    I have the following function, and it appears to set the var correctly, but then tries and executes the line as a command. Anyone know how to keep it from doing that?

    PHP Code:
    SMALL_FILE_PERCENTAGE=88
    MEDIUM_FILE_PERCENTAGE
    =10
    LARGE_FILE_PERCENTAGE
    =2
    DATA_TOTAL
    =1500
    DATA_TYPE
    =MB

    myfunction 
    (){
            
    PERCENTAGE=$((${1}_FILE_PERCENTAGE))
            
    DTYPE=$TOTAL_DATA_TYPE
            
    echo ==== PERCENTAGE ==== $PERCENTAGE #This works correctly

            
    if [[ "$DTYPE== "KB"  ]]; then
                    
    echo test kb
            elif 
    [[ "$DTYPE== "MB"  ]]; then
                 
    [B]   ${i}_TOTAL=123  <-------RIGHT HERE[/B]
            
    elif [[ "$DTYPE== "GB"  ]]; then
                    
    echo test gb
            elif 
    [[ "$DTYPE== "TB"  ]]; then
                    
    echo test tb
            fi
    }

    for 
    i in SMALL MEDIUM LARGE
    do
        
    myfunction $i
    done 
    Please don't modify the code, other than the "RIGHT HERE" code. I need it this way, but I am only giving a partial story with the code.

    Essentially, it will set a SMALL_TOTAL=12345, MEDIUM_TOTAL=blah, blah, blah. I am going to take the total and convert it into bytes based on the DATA_TYPE

    Thanks in advance

  2. #2
    Just Joined! jdh239's Avatar
    Join Date
    Sep 2006
    Posts
    55
    Solved it.... I had to add an 'export' or 'eval' before it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...