0

This is bash script

#!/bin/sh

filename=$1
path=data/$filename/$filename.csv
echo $path

aws s3 cp s3://bucket/key/$filename.csv $path

we written it for based on input parameter (filename), read the file from s3 bucket and move to our local directory. for example sh demo.sh sales . it will copy sales.csv file from source s3 bucket to local directory data/sales/sales.csv.

when we execute the command , it is showing some wired output like this .csvsales. but my expectation is data/sales/sales.csv. I tried ${filename},$filename and add double /. no luck,. But one think observed is if have this line

path=data/$filename/

and do echo it is printing data/sales. if i add additional string '/$filename.csv' it is not showing expected output.

Learn Hadoop
  • 2,760
  • 8
  • 28
  • 60
  • Try pasting your code into shellcheck.net Note also that it is `bash` ***not*** `batch`. – Mark Setchell Feb 24 '23 at 09:25
  • OMG. modified it – Learn Hadoop Feb 24 '23 at 09:27
  • 1
    It looks to me like something -- maybe the script, maybe its input, maybe both -- is in DOS/Windows format, rather than unix format. See ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) and ["How to convert Windows end of line in Unix end of line (CR/LF to LF)"](https://stackoverflow.com/questions/3891076/how-to-convert-windows-end-of-line-in-unix-end-of-line-cr-lf-to-lf). – Gordon Davisson Feb 24 '23 at 09:30
  • Tangentially, see also [When to wrap quotes around a shell variable.](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) Your script will break if a user passes in an argument with spaces or other shell metacharacters. – tripleee Feb 24 '23 at 09:31

0 Answers0