Create a new folder using bash without mkdir command
Solution 1
We generally don't play games here and artificially restrict what can and can't be used just for the fun of it. The builtin commands are
bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, com- popt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait
You can find out more about them using man builtins
.
Solution 2
This is not a 'builtins' solution (like touch is not a builtin), but it is a bash friendly solution.
Since this is a script, you imply planning. With this in mind, you create a directory, which you plan to use when the need arises within your script. When you need a new, empty directory, you will use the 'cp -r' command.
You would create a directory: /tmp/seed
In your script you need a directory called blue2013.
cp -r /tmp/seed ./blue123
Related videos on Youtube
demonofnight
Updated on September 18, 2022Comments
-
demonofnight almost 2 years
i'm creating a small shell script, and i want to know if is there a builtin command to create a new folder without using the mkdir command. I googled it but i wasn't able to find a way to do that.
I dont have any specific motivation or restriction to do that, is more a curiosity about the builtin commands on bash.
I imagine is somenthing like the touch file => > file
Regars
-
Dennis Williamson almost 11 yearsIt is useful to know alternatives for non-builtins such as
mkdir
orls
when working on a broken system. By the way,echo *
is the substitute forls
. -
Dennis Williamson almost 11 yearsIf you want to make sure the directory stays empty so the recursive copy only copies the directory,
chmod -w /tmp/seed
Also, you may want to put your seed directory somewhere else so it doesn't get automatically deleted.