shell script: manipulate input


Answer: 1

15 hours ago

I have this simple create directory command

mkdir -p /home/test/$1

I'm running this script like this

bash 2020/06/20/01

I want to get this passed argument and manipulate into following


how can I do it

Added by: Rollin Rogahn

Answer: 2

26 hours ago

You could do:

date=${1%/*}                     # 2020/06/20
dirname=${date//\//-}/${1##*/}   # 2020-06-20/01
mkdir -p "/home/test/$dirname"

Or perhaps

IFS=/ read -ra date_bits <<<"$1"   # date_bits=([0]="2020" [1]="06" [2]="20" [3]="01")
printf -v dirname "%s-%s-%s/%s" "${date_bits[@]}"
mkdir -p "/home/test/$dirname"
Added by: Milton Stark IV

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9