Skip to main content
Variables need to have explicit braces
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p ${dir}_${rnd}/C
   cp populate.sh ${dir}_${rnd}/C
done

rnd explanationExplanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.
  • while runs the read command for every line that find provides.
  • read assigns the directory from find to $dir.

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p ${dir}_${rnd}/C
   cp populate.sh ${dir}_${rnd}/C
done

rnd explanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p ${dir}_${rnd}/C
   cp populate.sh ${dir}_${rnd}/C
done

Explanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.
  • while runs the read command for every line that find provides.
  • read assigns the directory from find to $dir.
Variables need to have explicit braces
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p $dir_$rnd${dir}_${rnd}/C
   cp populate.sh $dir_$rnd${dir}_${rnd}/C
done

rnd explanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p $dir_$rnd/C
   cp populate.sh $dir_$rnd/C
done

rnd explanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p ${dir}_${rnd}/C
   cp populate.sh ${dir}_${rnd}/C
done

rnd explanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71

I wouldn't worry too much about -print0 as long as the file names are well formed. Below is an example that should do what you want:

rnd=$(tr -cd a-z0-9 < /dev/urandom | head -c5)
find . -maxdepth 1 -type d | while read dir; do
   mkdir -p $dir_$rnd/C
   cp populate.sh $dir_$rnd/C
done

rnd explanation

  • tr -cd deletes the complement of the specified pattern, alphanumerics in this case.
  • head -c5 takes the first five characters and exits.