Skip to main content
added 2 characters in body
Source Link
Hannu
  • 11k
  • 4
  • 25
  • 42
$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv .$file."$file" /target_dir; done < "/source_dir/list_of_files.txt'txt"'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing.

I assume you have a reason to use sh - if not, beware that sh often is a link to bash or something else (making it mimick sh)

Ubuntu 20.04:

$ ls -l `which sh`
lrwxrwxrwx 1 root root 4 mar 11  2021 /usr/bin/sh -> dash
$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing.

I assume you have a reason to use sh - if not, beware that sh often is a link to bash or something else (making it mimick sh)

Ubuntu 20.04:

$ ls -l `which sh`
lrwxrwxrwx 1 root root 4 mar 11  2021 /usr/bin/sh -> dash
$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv "$file" /target_dir; done < "/source_dir/list_of_files.txt"'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing.

I assume you have a reason to use sh - if not, beware that sh often is a link to bash or something else (making it mimick sh)

Ubuntu 20.04:

$ ls -l `which sh`
lrwxrwxrwx 1 root root 4 mar 11  2021 /usr/bin/sh -> dash
added 137 characters in body
Source Link
Hannu
  • 11k
  • 4
  • 25
  • 42
$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing. 

I assume you have a reason to use sh - if not, beware that sh often is a link to bash (making it mimick sh)I assume you have a reason to use sh - if not, beware that sh often is a link to bash or something else (making it mimick sh)

Ubuntu 20.04:

$ ls -l `which sh`
lrwxrwxrwx 1 root root 4 mar 11  2021 /usr/bin/sh -> dash
$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing.

I assume you have a reason to use sh - if not, beware that sh often is a link to bash (making it mimick sh).

$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing. 

I assume you have a reason to use sh - if not, beware that sh often is a link to bash or something else (making it mimick sh)

Ubuntu 20.04:

$ ls -l `which sh`
lrwxrwxrwx 1 root root 4 mar 11  2021 /usr/bin/sh -> dash
Source Link
Hannu
  • 11k
  • 4
  • 25
  • 42

$ bash -c "while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt"

The "-quotes allows $file to be evaluated as you hit ENTER, taking the null or existing value in your CURRENT shell as literal text, replacing $file with either that value or "" (the null string).

$ bash -c 'while IFS= read -r file; do echo mv .$file. /target_dir; done < /source_dir/list_of_files.txt'

Does not allow evaluation of $variable as you press ENTER, and thus leaves the TEXT $file as is, in place, until your one-liner is executing.

I assume you have a reason to use sh - if not, beware that sh often is a link to bash (making it mimick sh).