linux - Issue creating a folder then moving files into it within the same script -


i'm having problems moving files folder after create in shell script.

my script looks like:

#!/bin/bash echo -e "processing\033[36m" $1 "\033[0mwith german script"; if [ ! -d ${1%.dat} ];    echo -e "making directory\033[33m" ${1%.dat} "\033[0msince didn't exist...";     mkdir ${1%.dat}; fi 

...processing occurs here... (irrelevant issue)

if [ -d ${1%.dat} ];    mv useragents_$1 /${1%.dat}/useragents_$1;    mv summary_$1 /${1%.dat}/summary_$1;    more /${1%.dat}/useragents_$1; else    echo -e "\033[31merror: cannot move files folder.\033[0m"; fi 

as can see create folder if doesn't exist in top section , if exists move files folder in bottom section, problem doesn't create folder in time move files in (i'm assuming) when reaches lower code, error.

i tried using, sleep 5, slows down script , has no effect on error.

i appreciate advice.

errors below:

mv: cannot move `useragents_100_stns2_stns6.dat' `/100_stns2_stns6/useragents_100_stns2_stns6.dat': no such file or directory mv: cannot move `summary_100_stns2_stns6.dat' `/100_stns2_stns6/summary_100_stns2_stns6.dat': no such file or directory /100_stns2_stns6/useragents_100_stns2_stns6.dat: no such file or directory 

pass 1

your check:

if [ ! -d ${1%.dat} ]; 

should be:

if [ -d ${1%.dat} ]; 

you created directory; if directory, move stuff it.

typo in question

pass 2

you create:

mkdir ${1%.dat} 

you try move files:

mv useragents_$1 /${1%.dat}/useragents_$1; 

note leading slash in move compared create. make consistent.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -