LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   create multiple directories in bash? (https://www.linuxquestions.org/questions/programming-9/create-multiple-directories-in-bash-618390/)

colucix 07-06-2008 04:02 AM

Please, post the exact command line you've used along with the assignments of BASENAME, STARTDIR, ENDDIR. On my system it works fine:
Code:

$ BASENAME=test
$ STARTDIR=1
$ ENDDIR=12
$ mkdir $BASENAME$(seq -w -s " $BASENAME" $STARTDIR $ENDDIR)
$ ls
test01  test02  test03  test04  test05  test06
test07  test08  test09  test10  test11  test12


Count Zero 07-06-2008 07:41 AM

Hi, this is what I punched in:

Code:

mojoman@jukejoint:~/new$ BASEDIR=test
mojoman@jukejoint:~/new$ STARTDIR=1
mojoman@jukejoint:~/new$ ENDDIR=12
mojoman@jukejoint:~/new$ mkdir $BASENAME$(seq -w -s " $BASENAME" $STARTDIR $ENDDIR)
mojoman@jukejoint:~/new$ ls
01  02  03  04  05  06  07  08  09  10  11  12
mojoman@jukejoint:~/new$

Also:

Code:

mojoman@jukejoint:~/new$ bash --version
GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
mojoman@jukejoint:~/new$

Any ideas on what I'm doing wrong?


Thanks

makyo 07-06-2008 08:01 AM

Hi.

In many cases, nounset is a good friend:
Code:

#!/bin/bash3 -

# @(#) user3    Demonstrate use of nounset.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1)
echo

set -o nounset

BASEDIR=test
STARTDIR=1
ENDDIR=12
echo $BASENAME$(seq -w -s " $BASENAME" $STARTDIR $ENDDIR)

exit 0

Producing:
Code:

% ./user3
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 3.00.16(1)-release

./user3: line 14: BASENAME: unbound variable

cheers, makyo

colucix 07-06-2008 08:04 AM

Code:

./user3: line 14: BASENAME: unbound variable
Yes. Count Zero, you assigned BASEDIR then used BASENAME.

Count Zero 07-06-2008 08:34 AM

Quote:

Originally Posted by colucix (Post 3205520)
Code:

./user3: line 14: BASENAME: unbound variable
Yes. Count Zero, you assigned BASEDIR then used BASENAME.

Arghh! (slams forehead really hard into keyboard)

Thanks! That was it. I don't know how I missed it. I appreciate you giving your time, effort and expertise.

I'll also be using the nounset option in the future...

Cheers!


All times are GMT -5. The time now is 12:01 PM.