Polls

Topics

BASH Shell Frequently Asked Questions

Posted by Vivek on Friday November 30, 07 @1:18 pm

This document contains a set of frequently-asked questions concerning Bash, the GNU Bourne-Again Shell. Bash is a free and default command interpreter with advanced features for both interactive use and shell programming under Linux. Also don't forget TLDP bash guide / Advanced Bash-Scripting Guide.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. Manojg Says:

    Hi,

    I am using bash shell. I have a list of selected directories and want to loop over these directories. The code is like this:

    =========================================
    #!/bin/bash
    dir1=/home/abc/xyz1
    dir2=/home/abc/xyz2
    dir3=/home/cft/dsf
    ————
    ————

    x=1
    dir=”"
    while [ $x -le 8 ]; do
    echo $(”dir”$x)
    let x++
    done
    ===========================================

    In output it produces dir1, dir2, dir3 etc., not the full name directory as defined above. How should I do this?

    Thanks
    Manojg

  2. Zhiyi Says:

    See my solution

    #!/bin/bash

    #one approach is to use array
    dir=(/home/abc/xyz1 /home/abc/xyz2 /home/cft/dsf)
    x=0
    while [ $x -lt ${#dir[@]} ];
    do
    echo ${dir[x]}
    ((x++))
    done

    # another one is just use ‘for’
    echo “”
    dirs=”/home/abc/xyz1 /home/abc/xyz2 /home/cft/dsf”
    for dir in $dirs
    do
    echo $dir
    done

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , ~ Last updated on: December 27, 2007

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.