0

I am very new to the linux , i am trying to make a directories from the files which is present in the current working directory, one directory is created but another one is not creating it's throwing an error like mkdir: missing operand

for files in *.txt
do
folderName= echo $files | awk -F. '{print $1}';
mkdir $folderName;
done
3
  • Which one is not working? Better use $(basename $file .txt) to retrieve the base name of the file.
    – vanadium
    Sep 21 at 12:51
  • 1
    why do you assume $folderName has a value? :)
    – Rinzwind
    Sep 21 at 13:02
  • Use string manipulation instead: mkdir "${file%.*}", then you can skip this folderName thing altogether.
    – bac0n
    Sep 21 at 13:07
2

If you need the output of a command as a new variable, put the command between $(). Like this:

folderName=$(echo $files|awk -F. '{print $1} ';)

To see what you're doing, add another echo command to confirm that the folder name has been correctly constructed:

echo $folderName

before you do the mkdir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.