1

I want to run the following script from python:

temp=$(sky2xy image.fits 124.6456 -2.5517); arr=(${temp// / });

For that I am using the os.system() module:

import os
os.system('temp=$(sky2xy image.fits 124.6456 -2.5517); arr=(${temp// / });')

But I am getting an unexpected syntax error

sh: 1: Syntax error: "(" unexpected 512

The error is due to the parenthesis used in arr=(${temp// / })

How should I get rid of this error?

hitzg
  • 12,133
  • 52
  • 54
Aalok_G
  • 471
  • 7
  • 18
  • 1
    You're trying to do bash-specific stuff using `sh`. This is almost certainly a duplicate. – Tom Fenech Jun 26 '15 at 14:14
  • I would suggest that you do the minimum amount of work in the shell (i.e. `sky2xy image.fits 124.6456 -2.5517`), save the result in python and manipulate it from there. – Tom Fenech Jun 26 '15 at 14:22
  • I am actually trying to use Image magick, hence I am using the commandline. The complete script is as follows temp=$(sky2xy img.fits 124.6456 -2.5517); arr=(${temp// / }); X=${arr[4]};Y=${arr[5]}; convert -quiet img.fits -level 7.26470947266%,7.85173086528% -negate -fill transparent -stroke red -draw "circle $X,$Y `echo $X+5|bc`,$Y" -stroke black -draw "rectangle `echo $X-12|bc`,`echo $Y-12|bc` `echo $X+12|bc`,`echo $Y+12|bc`" -crop 50x50+`echo $X-25|bc`+`echo $Y-25|bc`\! -background transparent -flatten +repage img2.png; – Aalok_G Jun 26 '15 at 14:29
  • Fair enough, in that case I would suggest taking a look at one of the [python APIs](http://www.imagemagick.org/script/api.php) mentioned here. – Tom Fenech Jun 26 '15 at 14:31
  • By the way, you should [edit] your question to add further detail, rather than using the comments. – Tom Fenech Jun 26 '15 at 14:32
  • 1
    What's the point of replacing space with space? `${temp// / }`? – Jahid Jun 26 '15 at 14:43

1 Answers1

1
sh: 1: Syntax error: "(" unexpected 512
^^^

/bin/sh is not the same as /bin/bash (or /usr/bin/bash, as the case may be). You are attempting to use Bash-specific syntax in a shell that doesn't understand it.

twalberg
  • 59,951
  • 11
  • 89
  • 84