Skip to main content
Rollback to Revision 2
Source Link
agc
  • 7.4k
  • 4
  • 25
  • 54

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder.

When I run the script, I get the following error:

./findfile.sh: line 8: spam.txt: syntax error: invalid arithmetic operator (error token is ".txt")

Why would Bash think that this should be an integer, and how can this be fixed?

#!/bin/bash
#Find files from a list in a file and copy them to a common folder

mapfile -t filelist < filelist.txt

for i in ${filelist[i]}
do
    xargs find ~ -name '${filelist[i]}' | cp --parents ~/Documents/foundfiles/${filelist[i]}
done

Thanks, Jesse. Changing ${filelist[i]} to ${filelist[@]} fixed the integer problem!

Now, I have a brand new problem. The CP command wants a destination file name. I want the command to keep the old file name. The script does not recognize my code as a file name. What am I missing?

cp: missing destination file operand after '/home/crashwny/Documents/foundfiles/${filelist[@]}'

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder.

When I run the script, I get the following error:

./findfile.sh: line 8: spam.txt: syntax error: invalid arithmetic operator (error token is ".txt")

Why would Bash think that this should be an integer, and how can this be fixed?

#!/bin/bash
#Find files from a list in a file and copy them to a common folder

mapfile -t filelist < filelist.txt

for i in ${filelist[i]}
do
    xargs find ~ -name '${filelist[i]}' | cp --parents ~/Documents/foundfiles/${filelist[i]}
done

Thanks, Jesse. Changing ${filelist[i]} to ${filelist[@]} fixed the integer problem!

Now, I have a brand new problem. The CP command wants a destination file name. I want the command to keep the old file name. The script does not recognize my code as a file name. What am I missing?

cp: missing destination file operand after '/home/crashwny/Documents/foundfiles/${filelist[@]}'

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder.

When I run the script, I get the following error:

./findfile.sh: line 8: spam.txt: syntax error: invalid arithmetic operator (error token is ".txt")

Why would Bash think that this should be an integer, and how can this be fixed?

#!/bin/bash
#Find files from a list in a file and copy them to a common folder

mapfile -t filelist < filelist.txt

for i in ${filelist[i]}
do
    xargs find ~ -name '${filelist[i]}' | cp --parents ~/Documents/foundfiles/${filelist[i]}
done
First problem fixed, new error
Source Link
user289380
user289380

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder.

When I run the script, I get the following error:

./findfile.sh: line 8: spam.txt: syntax error: invalid arithmetic operator (error token is ".txt")

Why would Bash think that this should be an integer, and how can this be fixed?

#!/bin/bash
#Find files from a list in a file and copy them to a common folder

mapfile -t filelist < filelist.txt

for i in ${filelist[i]}
do
    xargs find ~ -name '${filelist[i]}' | cp --parents ~/Documents/foundfiles/${filelist[i]}
done

Thanks, Jesse. Changing ${filelist[i]} to ${filelist[@]} fixed the integer problem!

Now, I have a brand new problem. The CP command wants a destination file name. I want the command to keep the old file name. The script does not recognize my code as a file name. What am I missing?

cp: missing destination file operand after '/home/crashwny/Documents/foundfiles/${filelist[@]}'

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder.

When I run the script, I get the following error:

./findfile.sh: line 8: spam.txt: syntax error: invalid arithmetic operator (error token is ".txt")

Why would Bash think that this should be an integer, and how can this be fixed?

#!/bin/bash
#Find files from a list in a file and copy them to a common folder

mapfile -t filelist < filelist.txt

for i in ${filelist[i]}
do
    xargs find ~ -name '${filelist[i]}' | cp --parents ~/Documents/foundfiles/${filelist[i]}
done

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder.

When I run the script, I get the following error:

./findfile.sh: line 8: spam.txt: syntax error: invalid arithmetic operator (error token is ".txt")

Why would Bash think that this should be an integer, and how can this be fixed?

#!/bin/bash
#Find files from a list in a file and copy them to a common folder

mapfile -t filelist < filelist.txt

for i in ${filelist[i]}
do
    xargs find ~ -name '${filelist[i]}' | cp --parents ~/Documents/foundfiles/${filelist[i]}
done

Thanks, Jesse. Changing ${filelist[i]} to ${filelist[@]} fixed the integer problem!

Now, I have a brand new problem. The CP command wants a destination file name. I want the command to keep the old file name. The script does not recognize my code as a file name. What am I missing?

cp: missing destination file operand after '/home/crashwny/Documents/foundfiles/${filelist[@]}'

edited tags
Link
jesse_b
  • 41.6k
  • 14
  • 109
  • 163
Source Link
user289380
user289380
Loading