Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    [HELP] Very strange script problem

    I am having a very strange scripting problem. I'm hoping that someone can help.

    I am having a problem with a script running on a QNAP NAS device. It is running Linux version 2.6.24 (root NasX86-3) (gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)) #1 SMP Sat Jun 27 01:00:45 CST 2009. Bash version is GNU bash, version 3.2.0(1)-release-(i686-pc-linux-gnu).

    Create the following test file as test.conf:
    line1 = abc     def
    Please note there are five spaces between abc and def. At the command prompt type the following:
    [~] # /sbin/getcfg Test line1 -f test.conf
    abc     def
    [~] #
    As you can see the returned value is correct. Now create the following script and name it test:
    /sbin/getcfg Test line1 -f ./test.conf
    Now execute the script. The output should look correct.
    [~] # ./test
    abc     def
    [~] #
    Now modify the script so it looks like this:

    xxx=`/sbin/getcfg Test line1 -f ./test.conf`
    echo $xxx
    Now execute it.
    [~] # ./test
    abc def
    [~] #
    Notice that the output is wrong. The five spaces between the abc and def have been reduced to one space. Why is assigning the output to a variable changing the output? What has happened and how do I prevent this from happening? This is really screwing up some code I have and I need a solution.


    If I execute the command directly from the command line it works. It only messes up when run from a script.

    [~] # xxx="`/sbin/getcfg Test line1 -f ./test.conf`"
    [~] # set
    xxx='abc     def'


  2. #2
    Anyone have any ideas??

Posting Permissions

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