Help me with mkdir command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me with mkdir command
# 1  
Old 11-08-2010
Help me with mkdir command

Hi, please help me with this small script

Code:
#!/bin/sh 

curdir=`pwd`
n20=$curdir'/n20/'
msat=$curdir'/n20/msat/'

if [ ! -d $n20 ]
   then
   mkdir $n20
fi

if [ ! -d $msat ]
   then
   mkdir $msat
fi

for a in 30 40 50 60 70 80
do
    $aa=$msat'a'$a
    mkdir $aa
done

The ouput is
Quote:
.../n20/msat/a30: not found
mkdir: missing operand
Try `mkdir --help' for more information.
I don't understand what I am missing.

When I replace "mkdir $aa" with "echo $aa". I get the output like this:
Quote:
.../n20/msat/a30: not found
Why there is 'not found' here? How should I correct it? Could you please explain for me?
# 2  
Old 11-08-2010
Try this for last for loop should be
Code:
for a in 30 40 50 60 70 80
do
    aa=${msat}a${a}
    mkdir $aa
done

The $aa should be aa only
# 3  
Old 11-08-2010
Quote:
Originally Posted by sanjaypraj
Try this for last for loop should be
Code:
for a in 30 40 50 60 70 80
do
    aa=${msat}a${a}
    mkdir $aa
done

The same error as mine.
Quote:
The $aa should be aa only
This will create the folder with name "aa". I want to create folder a30, a40,...
# 4  
Old 11-08-2010
Code:
#!/bin/ksh
curdir=`pwd`
n20=$curdir/n20
msat=$curdir/n20/msat
if [ ! -d "$n20" ]
then
   mkdir "$n20"
fi
if [ ! -d $msat ]
then
   mkdir $msat
   if [ $? -ne -0 ]
   then
      echo "Failed mkdir $msat"
   fi
fi
for a in 30 40 50 60 70 80
do
   aa=${msat}/a"$a"
   mkdir -p $aa
  if [ $? -ne -0 ]
   then
      echo "Failed mkdir $aa"
  fi

done


Last edited by pludi; 11-08-2010 at 11:12 AM..
This User Gave Thanks to BeefStu For This Post:
# 5  
Old 11-08-2010
Thanks a lot Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cd then mkdir from script

Importing images from a camera (or two). I sort by date (1901 this month). Currently (failing) if ] then echo "Found Panasonic G9X" #echo "List files on camera" #ls ${pana}/* . chxdir.sh ${photos}/$mn I want to change directory to a fixed base ($photos)/$mn... (10 Replies)
Discussion started by: dpawson
10 Replies

2. UNIX for Beginners Questions & Answers

Mkdir

hi linux expert what is a difference between: mkdir test and mkdir ./test and also if ( -e /test ) then and if ( -e ./test ) then thanks in advance Please use icode or code tags next time for your code and data (1 Reply)
Discussion started by: abdossamad2003a
1 Replies

3. Homework & Coursework Questions

Mkdir

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Do the procedure, which if there are 5 parameters then it creates 4 directories with names of 4 parameters, in... (2 Replies)
Discussion started by: bolones
2 Replies

4. Linux

mkdir command

Hi all, i am new to Linux and need some help. I used the command: mkdir super Directory super is created When i try to change to this directory using: cd /super I get: bash: cd: /super: No such file or directory when i use: rm super I get: rm: cannot remove 'super': Is a directory What... (5 Replies)
Discussion started by: Deside
5 Replies

5. Shell Programming and Scripting

[Solved] how to create multiple directory in one mkdir command

Hi, Unix Gurus, - I have a simple question, I need create multiple directory. I use mkdir {dir1, dir2, dir3) I got one directory as {dir1, dir2, dir3} I searched @ google, I got answer as above code.:wall::confused: Anybody has any idea Thanks in advance ---------- Post updated... (3 Replies)
Discussion started by: ken002
3 Replies

6. UNIX for Dummies Questions & Answers

mkdir unix command

hi.. i want to know how mkdir command make directory in linux....?? (2 Replies)
Discussion started by: rinkugarg
2 Replies

7. Shell Programming and Scripting

Cp/Mkdir and spaces

I am having trouble using cp and mkdir commands on a small script. The problem is I have spaces what I am trying to mkdir and then copy. Any suggestions on how I can solve this problem? I've tried searching online. while read linefile do echo mkdir -p $CPP$linefile | cut -d / -f 1-5,8-12 ... (10 Replies)
Discussion started by: imagiro1
10 Replies

8. UNIX for Advanced & Expert Users

mkdir

Is there ant way to increase max number of folders in the directory from the 32766: Problem UFS: shell>mkdir mmm mkdir: mmm: Too many links But there are no links, just folders. shell>ls | wc -l 32766 (3 Replies)
Discussion started by: mirusnet
3 Replies

9. Shell Programming and Scripting

mkdir

Hi, I look for a script to create 150 directories : d000 d001 d002 ... ... d149 would you help me please ? I think it would be for i mkdir d$i Many thanks. PS : #uname -a AIX fserver 3 5 0050691A4C00 (2 Replies)
Discussion started by: big123456
2 Replies

10. UNIX for Dummies Questions & Answers

What's the problem with the command of mkdir

The message is: #mkdir /home/ade mkdir:Failed to make directory "/home/ade",Operation not applicable. What's the problem? :mad: (3 Replies)
Discussion started by: new_hand
3 Replies
Login or Register to Ask a Question