“Command not found” piping a variable to cut when output stored in a variable [duplicate]
问题 This question already has answers here : How to pass the value of a variable to the stdin of a command? (9 answers) Closed 3 years ago . In a bash script I am using a variable to hold a path like this: MY_DIR=/just/a/string/to/my/path And I want to remove the last two parts of it so it looks like this: /just/a/string I am using 'cut' to do it, like this: echo $MY_DIR | cut -d'/' -f-4 The output is what I expect. Fine. But I want to store in an other variable, like this: MY_DIR2=$($MY_DIR |