Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 16 of 16
Hi. Originally Posted by Cabhan This may work...you can't remove the echo line, because then you have if, no statement, then an else. The new echo statement echoes a newline ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,283

    Hi.
    Quote Originally Posted by Cabhan
    This may work...you can't remove the echo line, because then you have if, no statement, then an else. The new echo statement echoes a newline to /dev/null.
    The echo to /dev/null is fast. I usually advise the use of ":" to fill those little gaps --
    Code:
           : [arguments]
                  No  effect;  the command does nothing beyond expanding arguments
                  and performing any specified redirections.  A zero exit code  is
                  returned. -- man bash
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  2. #12
    Just Joined! Tomato's Avatar
    Join Date
    Aug 2006
    Location
    HKSAR, China
    Posts
    63
    The echo to /dev/null is fast. I usually advise the use of ":" to fill those little gaps --
    I don't really understand what you are talking about.
    Can you show some codes?
    Thanks

  3. #13
    Just Joined! Tomato's Avatar
    Join Date
    Aug 2006
    Location
    HKSAR, China
    Posts
    63
    Hey could you help me with something else?

    I actually have 5 different mysql tables to load the field values from. I tried to write a shell script to connect to the db and run the queries automatically, but within the shell, I can't use backticks (the field name has a space in it). I replaced the backticks with single and double quotes, but instead of getting the field value, I get the field name.
    Do you know how I could write this script and get it to work? Obviously, it makes sense to try to automate this:


    Code:
    #!/bin/bash
    echo starting to get all current mls records
    mysql dbname --user=uname <<**
    SELECT `MLS No` from idx_4 into outfile '/tmp/idx4.txt' ; SELECT `MLS No` from idx_5 into outfile '/tmp/idx5.txt' ; exit
    **
    echo finished getting mls numbers
    from the command prompt, mysql>, the above code will work, but from the shell script it won't. What can I do?
    I think you can use a variable to store the column field. Let's see the code

    Code:
    column="MLS No"
    SELECT "$column" from idx_4 into outfile '/tmp/idx4.txt' ; SELECT "$column" from idx_5 into outfile '/tmp/idx5.txt' ; exit
    I think now you can run the script well.
    Hope it can give a hand to you.

  4. #14
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,283
    Hi.
    Quote Originally Posted by Tomato
    I don't really understand what you are talking about.
    Can you show some codes?
    Thanks
    Here's an example of the use of colon for debugging. When one writes shell scripts, one often needs to do debugging output, typically with echo statements. Once the code is running correctly, we might be tempted to remove the debugging output statements. However, we can arrange to leave the statements in the code and use a simple triggering mechanism to turn output on and off as we choose.
    Code:
    #!/bin/sh
    
    # @(#)  s1      Demonstrate use of colon, :, as a null command.
    
    debug="echo"
    debug=":"
    
    i=0
    while [ $i -lt 5 ]
    do
            $debug "The value of i is $i"
            i=$(( i+1))
    done
    
    echo "The final value of i is $i."
    Running the code as it is will not produce the output from inside the loop. However, if you interchange the assignment statements for the debug variable, you will see that intermediate, debugging, output is enabled. One can keep the statements in the code, to be used as needed when the inevitable modifications are made.

    In other instances, a command sometimes is required, such as between and if and an else, and the colon command is often a good choice ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #15
    Just Joined! Tomato's Avatar
    Join Date
    Aug 2006
    Location
    HKSAR, China
    Posts
    63
    Here's an example of the use of colon for debugging. When one writes shell scripts, one often needs to do debugging output, typically with echo statements. Once the code is running correctly, we might be tempted to remove the debugging output statements. However, we can arrange to leave the statements in the code and use a simple triggering mechanism to turn output on and off as we choose.
    That means we can use ":" to comment that line and do nothing there but it still is counted as a command?

  6. #16
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    It basically means that ':' can be used when you need to place a command, but don't want anything to happen, as in the above if-else problem I discussed.

    drl is showing another application of this, that you can easily toggle debugging output. The ':' command does absolutely nothing.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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