BASH Shell Frequently Asked Questions

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Manojg Mar 23, 2008 @ 16:04


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


    while [ $x -le 8 ]; do
    echo $(“dir”$x)
    let x++

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


  • Zhiyi Apr 16, 2008 @ 21:48

    See my solution


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

    # another one is just use 'for'
    echo ""
    dirs="/home/abc/xyz1 /home/abc/xyz2 /home/cft/dsf"
    for dir in $dirs
    echo $dir

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum