Skip to main content
Make even more POSIX, formatting
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

POSIX sh using a while loop

Reading names from find command.

find . ! -maxdepthpath 1. -prune -type f -name 'image*png' |  
while IFS= read -r f; do
  mv -v "$f" "$(echoprintf '%s\n' "$f" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do 
 mv -vmv "$f" "$(echoprintf "$f"|sed'%s\n' "$f" | sed -e 's/^\.\/image//' - )"; "
done < flist

Both of these approaches assume pathnames have no embedded newlines.

POSIX sh using a while loop

Reading names from find command.

find . -maxdepth 1 -type f -name 'image*png' | while IFS= read -r f; do
  mv -v "$f" "$(echo "$f" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do mv -v "$f" "$(echo "$f"|sed -e 's/^\.\/image//' - )"; done < flist

POSIX sh using a while loop

Reading names from find command.

find . ! -path . -prune -type f -name 'image*png' | 
while IFS= read -r f; do
  mv "$f" "$(printf '%s\n' "$f" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do 
  mv "$f" "$(printf '%s\n' "$f" | sed -e 's/^\.\/image//' - )"
done < flist

Both of these approaches assume pathnames have no embedded newlines.

typos $i should be $f
Source Link
X Tian
  • 10.7k
  • 3
  • 35
  • 51

POSIX sh using a while loop

Reading names from find command.

find . -maxdepth 1 -type f -name 'image*png' | while IFS= read -r f; do
  mv -v "$i""$f" "$(echo "$i""$f" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do mv -v "$f" "$(echo "$i"|sed"$f"|sed -e 's/^\.\/image//' - )"; done < flist

POSIX sh using a while loop

Reading names from find command.

find . -maxdepth 1 -type f -name 'image*png' | while IFS= read -r f; do
  mv -v "$i" "$(echo "$i" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do mv -v "$f" "$(echo "$i"|sed -e 's/^\.\/image//' - )"; done < flist

POSIX sh using a while loop

Reading names from find command.

find . -maxdepth 1 -type f -name 'image*png' | while IFS= read -r f; do
  mv -v "$f" "$(echo "$f" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do mv -v "$f" "$(echo "$f"|sed -e 's/^\.\/image//' - )"; done < flist
Source Link
X Tian
  • 10.7k
  • 3
  • 35
  • 51

POSIX sh using a while loop

Reading names from find command.

find . -maxdepth 1 -type f -name 'image*png' | while IFS= read -r f; do
  mv -v "$i" "$(echo "$i" | sed -e 's/^\.\/image//' - )"
done

Reading names from a file

while IFS= read -r f; do mv -v "$f" "$(echo "$i"|sed -e 's/^\.\/image//' - )"; done < flist