How to Resolve Mkdir: Missing Operand Error in Linux?

How to Resolve Mkdir: Missing Operand Error in Linux?

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

1 Answer

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

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.