this post was submitted on 07 Oct 2024
12 points (100.0% liked)
Bash
779 readers
1 users here now
Talk about the Bash Shell and Bash scripting
founded 4 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
already answered the question
Would like to add, don't do this or shoulda used Python.
Manipulating strings in bash is a mistake and creates spaghetti code. This goes for sed and awk as well.
Python equivalent
In one line, capturing the output into a bash variable
ret=$(python -c 'str_x = "abcde"; pos = str_x.index("d"); ret = str_x[:pos]; print(ret)')
Thought this was a bash community
it's a bash community as long as bash is the right tool for the job. For text manipulation, not so much. In Python can also do some really stupid things. Then will get advice. They'll say,
just don't do that
Which is what i'm doing here.
just don't do that