Is there an error in this

I'm trying to upload a jpg file to PiXhost - Free Image Hosting. The website is seemingly simple. What have I done wrong in the following code, which doesn't work:

filename=filename.jpg
post_data=$(echo "img[]=@"$filename",,,,&content_type=1&gallery_name=&tos=on")

post_string=$(echo "curl -L -F "\"$post_data\"" https://pixhost.to/classic-upload/ > test.html")

eval $post_string
firefox test.html

  

If I were successful, the command "firefox test.html" should show the image.

I am not exactly sure what you are trying to achieve here with the subshells and the echo s. If you want to assign a string to a variable you simply do:

post_data="img[]=@${filename},,,,&content_type=1&gallery_name=&tos=on"

and likewise

post_string="curl -L -d \"${post_data}\" https://pixhost.to/classic-upload/ > test.html"

Finally, instead of using the "atomic-bomb-equivalent of shell-scripting", aka eval , you can simply do:

$post_string

to execute the command you set together in assigning the string before.

I hope this helps.

bakunin

2 Likes