This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Need help with shell script for ftp get PATRIC bacterial sequences

Hi,

I am having trouble getting the below to work. The standard outs I am getting from the command line are at the bottom, as is the smallarray.txt test file. I think it is a syntax thing... but I would be much obliged for your constructive comments:

#! /bin/bash
# To make a library of PATRIC .fna sequences 

cd /Users/bgold/Documents/PATRIC/

declare -a array

array=$(<smallarray.txt)

HOST='ftp.patricbrc.org'
USER='anonymous'
PASSWD='redacted@gmail.com'

#iterative part

for i in `seq 0 3`; do

VARIABLE=$i

FOLDER=${array["$VARIABLE"]}
FILE=${array["$VARIABLE"]}.fna

ftp --no-login $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD

cd /patric2/patric3/genomes

cd $FOLDER

get $FILE

quit

END_SCRIPT

exit 0

done

##commented small array below

#####smallarray.txt########
##9.107
##9.108
##9.109
##9.11

###command line complaint from my Mac
#Berts-MacBook-Pro:PATRIC bgold$ ./experimentalscript.sh
#?Invalid command
#?Invalid command
#?Invalid command
#9.107: No such file or directory
#?Invalid command
#?Invalid command
#?Invalid command
ftp arrays patric microbiome shell scripts

Have you tried running these command step by step on the shell? If they work when you copy-paste from the script and running the script does not work, it'll be easier to zero in on the problem.

Also, I'd recommend against using variable names like array and using a cd within a script (unless you have really good cause). A script should be able to be invoked from any directory and only create new files/change existing files (with appropriate caution) under the present working directory. It is dangerous to change files elsewhere (especially by non-pro users in non-system locations).

content deleted by user

You have not addressed my question either - did you run the commands line by line on the command prompt instead of just trying the script?

1 answer

content deleted by user

Do not add an answer unless you're answering the top level question. This should be a reply to my comment. Please follow the steps below to do this:

  1. Copy the contents of your reply from this answer (you can edit this answer (Ctrl/Cmd + click the link to open it in a new tab) and do a Select All -> Copy there).
  2. Click on "Add Reply" on my's comment here: C: Need help with shell script for ftp get PATRIC bacterial sequences
  3. Paste the copied text
  4. Click on the green "Add Comment" button
  5. Click on moderate back in your answer here: A: Need help with shell script for ftp get PATRIC bacterial sequences
  6. Choose Delete Post
  7. Click on the blue Submit button.

Once you do this, I will respond to your question.

Thank you!

Log in to answer this question.