I need to pass a string containing slashes to sed to extract some values from it, but when I try to do so it treats it as a directory/file and throws a "No such directory or file" error instead. I'm assuming this is because it reads it as a path and tries to find the file when it is not the intended effect. Example:
my_value="my/value"
operand="$($my_value | sed -n -e 's/^\(.*\)\/.*/\1/p')"
# Expected echo $operand : my
Note: I am new to bash scripts so this could be the wrong way to go about this
operand=${my_value%/*}
oroperand=${my_value%%/*}
depending whether you want to remove the shortest or the longest matching suffix – steeldriver May 11 '20 at 22:59