unix - Separating characters of a string, bash shell -


i'm trying write script takes 1 string argument, divides string characters , uses characters create directory.

ex: "./adduser asd" should create directory named "a" inside directory script located, has create directory named "s" child directory of "a". similarly, directory named "d" has created inside directory "s".

i'm stuck, can please help?

thanks in advance.

one possible solution mkdir -p:

echo asd | sed 's:.:&/:g' | xargs -n1 -i % mkdir -p "%" 

or usual eliminating useless echo :) , script format

#/bin/bash <<< "$1" sed 's:.:&/:g' | xargs -n1 -i % mkdir -p "%" 

this can used as

< filename sed 's:.:&/:g' | xargs -n1 -i % mkdir -p "%" 

the names in file filename

or

mkdir -p $(echo asd | sed 's:.:&/:g') 

or

mkdir -p $(sed 's:.:&/:g' <<< "asd") 

as usually, spaces , special chars make troubles...


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -