Bash arrays and permissions denied?
I have an array of names:
Code:
Name_List=(TAR1 MIR L2) For each name in the array, open a blank file called name.txt So for example, in the end, I should have TAR1.txt MIR.txt L2.txt Each being an empty file. Here is my attempt: Code:
#!/usr/bin/bash processdata.sh: line 20: $temp_file: ambiguous redirect MIR processdata.sh: line 20: $temp_file: ambiguous redirect L2 processdata.sh: line 20: $temp_file: ambiguous redirect Can anybody help me out? It would be quite appreciated. |
I think you're looking for something like this:
Code:
teddy@office~/$ Name_List=( TAR1 MIR L2 ) temp_file= echo ${Name_List[$index]} > $temp_file What exactly do you assign to the variable temp_file? |
Quote:
Than kyou for posting the working code, I will try to fix mine now. |
Note that in a variable assignment, there must be no spaces on either side of the '='.
|
Also, in order to use the output of one command sequence inside another command (such as variable setting), you need to enclose it in the $() command substitution structure. And wrap the whole thing in quotes for good measure.
Code:
temp_file="$(echo ${Name_List[$index]})" Unless you really intended to do something like this: Code:
temp_file="filename.txt" |
Actually, if you just want an empty file, use
touch filename much easier to read/debug than '> filename' |
All times are GMT -5. The time now is 01:09 PM. |