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
Post a Comment