Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

Write a shell script capable of doing the following: 1. Create a directory "preFinal" in your home directory. In case that such directory exist, rename the existing one into "preFinal.000" and then create empty directory preFinal. While renaming existing preFinal into preFinal.000 you may discover that preFinal.000 also exists, so it needs to be renamed into preFinal.001 and so on. 2. Create empty files "a", "b", "c", etc in directory preFinal in the amount that match the number of directories preFinal*

ganeshie8 (ganeshie8):

have u started coding... can u share ur code so we can start from there ?

OpenStudy (anonymous):

#!/bin/bash # benProj.sh mkdir benProj/a benProj=0 if [ ls '-d "$0" -gt 1' ]; then mv "$0" "$0.000+.001" mkdir "$0" fi

OpenStudy (anonymous):

but i think the line for If is wrong. and i have no clue as to where to go from here! please help!!

OpenStudy (anonymous):

i used benProj instead of preFinal, so i can get enough practice before i can actually do my assignment

ganeshie8 (ganeshie8):

ok gimme sometime

OpenStudy (anonymous):

absolutely. Thank you!

ganeshie8 (ganeshie8):

``` #!/bin/bash dir="preFinal" if [ -d $dir ]; then echo "dir exists, moving..." i=0 for dir_bkp in `ls -lrt | egrep "preFinal*" | awk '{print $NF}' | sort -nr`; do #next=$(ls -lrt | egrep "preFinal*" | awk '{print $NF}' | sort -n | tail -n 1 | sed 's/^.*\.//') next=$(echo "$dir_bkp" | sed 's/^.*\.//') ((next++)) next="00$next" echo $next mv $dir_bkp $dir.$next ((i++)) done mkdir $dir else mkdir $dir fi ```

ganeshie8 (ganeshie8):

it does the part 1. part 2 see if u can do it yourself... if u get stuck ping me

OpenStudy (anonymous):

okay. Thank you. I will ping you if i get stuck!

ganeshie8 (ganeshie8):

good luck!

OpenStudy (anonymous):

what does dir_bkp mean?

ganeshie8 (ganeshie8):

dir_bkp is a loop variable

ganeshie8 (ganeshie8):

for loop iterates over preFinal* dirs, each time it assings the directory to this dis_bkp variable

OpenStudy (anonymous):

i got cha

ganeshie8 (ganeshie8):

ok great :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!