Skip to main content
added 33 characters in body; edited title
Source Link
Marcus Müller
  • 52.9k
  • 4
  • 80
  • 123

Ad Asterix Add Asterisk to a path Variable?

I need to use *.* at the end of a Path that is stored in a variable. Also just one "*" should be OK as well.

finally I want to move files in folders with same name. With a static Path like /share/test/temp/* the for loop worked. Now I have different usernames and the search folder for the for loop changes. Therefore I need a varible there. This doesnt work:

    destDir= $Startdir/$username/
a=$destDir/*.*

for file in $a  ; do
  tmp=${file:0:4};
  filenew=${file%.*}"($tmp)";
  mkdir -- "$filenew";
  mv -- "$file" "$filenew";  
done

I have tried to escape, single and doppledouble marks and backtipsbackticks.

a=$destDir/. # not working a="$destDir/*" # not working a= $destDir'/*' # not working a="$destDir/'*.*" # not working

a=$destDir/*.*      # not working
a="$destDir/\*"     # not working
a= $destDir'/\*'    # not working
a="$destDir/'\*.\*" # not working

How can I make a pure sting with asterix in it, that will be substitued in the for loop? Or is there any other option to pass a variable to a for loop that stores a path and for knows that he has to search very file in that path?

I would perfer a for loop than find $destDir -name ..

Ad Asterix to a path Variable?

I need to use *.* at the end of a Path that is stored in a variable. Also just one "*" should be OK as well.

finally I want to move files in folders with same name. With a static Path like /share/test/temp/* the for loop worked. Now I have different usernames and the search folder for the for loop changes. Therefore I need a varible there. This doesnt work:

    destDir= $Startdir/$username/
a=$destDir/*.*

for file in $a  ; do tmp=${file:0:4}; filenew=${file%.*}"($tmp)"; mkdir -- "$filenew"; mv -- "$file" "$filenew"; done

I have tried to escape, single and dopple marks and backtips.

a=$destDir/. # not working a="$destDir/*" # not working a= $destDir'/*' # not working a="$destDir/'*.*" # not working

How can I make a pure sting with asterix in it, that will be substitued in the for loop? Or is there any other option to pass a variable to a for loop that stores a path and for knows that he has to search very file in that path?

I would perfer a for loop than find $destDir -name ..

Add Asterisk to a path Variable?

I need to use *.* at the end of a Path that is stored in a variable. Also just one "*" should be OK as well.

finally I want to move files in folders with same name. With a static Path like /share/test/temp/* the for loop worked. Now I have different usernames and the search folder for the for loop changes. Therefore I need a varible there. This doesnt work:

    destDir= $Startdir/$username/
a=$destDir/*.*

for file in $a  ; do
  tmp=${file:0:4};
  filenew=${file%.*}"($tmp)";
  mkdir -- "$filenew";
  mv -- "$file" "$filenew"; 
done

I have tried to escape, single and double marks and backticks.

a=$destDir/*.*      # not working
a="$destDir/\*"     # not working
a= $destDir'/\*'    # not working
a="$destDir/'\*.\*" # not working

How can I make a pure sting with asterix in it, that will be substitued in the for loop? Or is there any other option to pass a variable to a for loop that stores a path and for knows that he has to search very file in that path?

I would perfer a for loop than find $destDir -name ..

Source Link

Ad Asterix to a path Variable?

I need to use *.* at the end of a Path that is stored in a variable. Also just one "*" should be OK as well.

finally I want to move files in folders with same name. With a static Path like /share/test/temp/* the for loop worked. Now I have different usernames and the search folder for the for loop changes. Therefore I need a varible there. This doesnt work:

    destDir= $Startdir/$username/
a=$destDir/*.*

for file in $a  ; do tmp=${file:0:4}; filenew=${file%.*}"($tmp)"; mkdir -- "$filenew"; mv -- "$file" "$filenew"; done

I have tried to escape, single and dopple marks and backtips.

a=$destDir/. # not working a="$destDir/*" # not working a= $destDir'/*' # not working a="$destDir/'*.*" # not working

How can I make a pure sting with asterix in it, that will be substitued in the for loop? Or is there any other option to pass a variable to a for loop that stores a path and for knows that he has to search very file in that path?

I would perfer a for loop than find $destDir -name ..