0

i have a script python which take as input a variable generated in bash:

source <(python3 ${bin_path}/jd_to_date.py ${data[0]0:5})

where data is a an array composed by a lot of value like these: 57235003472222219e+04.....and ${data[0]0:5} should be 57235

in python i use this code for reading the variable:

mjd = sys.argv[1]

but when i execute the bash program i obtain this output:

Traceback (most recent call last):
File "/opt/project/demetra/bin/jd_to_date.py", line 47, in <module>
jd_to_mjd()
File "/opt/project/demetra/bin/jd_to_date.py", line 8, in jd_to_mjd
jd_n=int(mjd)+2400000.5
ValueError: invalid literal for int() with base 10: '003472222219e+04'

it seems that the read variable is the second part of the data value. How it is possible?

Many thanks

1 Answer 1

2

data[0]=57235003472222219e+04; echo ${data[0]0:5} as noted prints "003472222219e+04"

I'm pretty sure you want:

data[0]=57235003472222219e+04; echo ${data[0]:0:5} which prints out the desired "57235"

(where the key change is the : between the closing square bracket and the zero)

Sign up to request clarification or add additional context in comments.

1 Comment

:D sorry, are too many hours i am on the screen. I will take a cofee...thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.