Score:0

How to resolve mkdir : missing operand error in linux?

id flag

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
vanadium avatar
cn flag
Which one is not working? Better use $(basename $file .txt) to retrieve the base name of the file.
cn flag
why do you assume $folderName has a value? :)
bac0n avatar
cn flag
Use string manipulation instead: `mkdir "${file%.*}"`, then you can skip this folderName thing altogether.
Score:2
uz flag
Jos

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.