Replace slash in to empty in bash



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Let's suppose I have this results:



CMD_VAL = 'test/'
echo $CMD_VAL
=> test/

echo "$CMD_VAL"|sed 's#/##g'
=>test


but,



PRO_VAL = "$CMD_VAL"|sed 's#/##g'
echo $PRO_VAL


this returns



=> "test/ is a directory"


How should it need to change in order to get the "test" into a variable as a string?










share|improve this question



















  • 1





    Your Bash syntax is all wrong. Please post the actual commands you're running.

    – ruakh
    Nov 15 '18 at 16:09











  • You are getting what appears to be an error message in trying to run test/ as a command, not the contents of PRO_VAL (which remains empty, so the "output" of echo $PRO_VAL appears after the error message. sed never actually produces any output, as it had no input.)

    – chepner
    Nov 15 '18 at 16:11











  • if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW_PROJECT_DIR" != "" ]; then echo $CMD_PRO_NAME_VAL echo "$CMD_PRO_NAME_VAL"|sed 's#/##g'

    – Hiranya Kavishani
    Nov 15 '18 at 16:12












  • here $CMD_PRO_NAME_VAL = test/ and echo "$CMD_PRO_NAME_VAL"|sed 's#/##g' I got it as "test". I want to take it to variable and print

    – Hiranya Kavishani
    Nov 15 '18 at 16:13












  • @chepner yes.how should I fix it?

    – Hiranya Kavishani
    Nov 15 '18 at 16:21

















0















Let's suppose I have this results:



CMD_VAL = 'test/'
echo $CMD_VAL
=> test/

echo "$CMD_VAL"|sed 's#/##g'
=>test


but,



PRO_VAL = "$CMD_VAL"|sed 's#/##g'
echo $PRO_VAL


this returns



=> "test/ is a directory"


How should it need to change in order to get the "test" into a variable as a string?










share|improve this question



















  • 1





    Your Bash syntax is all wrong. Please post the actual commands you're running.

    – ruakh
    Nov 15 '18 at 16:09











  • You are getting what appears to be an error message in trying to run test/ as a command, not the contents of PRO_VAL (which remains empty, so the "output" of echo $PRO_VAL appears after the error message. sed never actually produces any output, as it had no input.)

    – chepner
    Nov 15 '18 at 16:11











  • if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW_PROJECT_DIR" != "" ]; then echo $CMD_PRO_NAME_VAL echo "$CMD_PRO_NAME_VAL"|sed 's#/##g'

    – Hiranya Kavishani
    Nov 15 '18 at 16:12












  • here $CMD_PRO_NAME_VAL = test/ and echo "$CMD_PRO_NAME_VAL"|sed 's#/##g' I got it as "test". I want to take it to variable and print

    – Hiranya Kavishani
    Nov 15 '18 at 16:13












  • @chepner yes.how should I fix it?

    – Hiranya Kavishani
    Nov 15 '18 at 16:21













0












0








0








Let's suppose I have this results:



CMD_VAL = 'test/'
echo $CMD_VAL
=> test/

echo "$CMD_VAL"|sed 's#/##g'
=>test


but,



PRO_VAL = "$CMD_VAL"|sed 's#/##g'
echo $PRO_VAL


this returns



=> "test/ is a directory"


How should it need to change in order to get the "test" into a variable as a string?










share|improve this question
















Let's suppose I have this results:



CMD_VAL = 'test/'
echo $CMD_VAL
=> test/

echo "$CMD_VAL"|sed 's#/##g'
=>test


but,



PRO_VAL = "$CMD_VAL"|sed 's#/##g'
echo $PRO_VAL


this returns



=> "test/ is a directory"


How should it need to change in order to get the "test" into a variable as a string?







bash macos resx slash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 16:09









chepner

263k36253345




263k36253345










asked Nov 15 '18 at 16:05









Hiranya KavishaniHiranya Kavishani

72




72







  • 1





    Your Bash syntax is all wrong. Please post the actual commands you're running.

    – ruakh
    Nov 15 '18 at 16:09











  • You are getting what appears to be an error message in trying to run test/ as a command, not the contents of PRO_VAL (which remains empty, so the "output" of echo $PRO_VAL appears after the error message. sed never actually produces any output, as it had no input.)

    – chepner
    Nov 15 '18 at 16:11











  • if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW_PROJECT_DIR" != "" ]; then echo $CMD_PRO_NAME_VAL echo "$CMD_PRO_NAME_VAL"|sed 's#/##g'

    – Hiranya Kavishani
    Nov 15 '18 at 16:12












  • here $CMD_PRO_NAME_VAL = test/ and echo "$CMD_PRO_NAME_VAL"|sed 's#/##g' I got it as "test". I want to take it to variable and print

    – Hiranya Kavishani
    Nov 15 '18 at 16:13












  • @chepner yes.how should I fix it?

    – Hiranya Kavishani
    Nov 15 '18 at 16:21












  • 1





    Your Bash syntax is all wrong. Please post the actual commands you're running.

    – ruakh
    Nov 15 '18 at 16:09











  • You are getting what appears to be an error message in trying to run test/ as a command, not the contents of PRO_VAL (which remains empty, so the "output" of echo $PRO_VAL appears after the error message. sed never actually produces any output, as it had no input.)

    – chepner
    Nov 15 '18 at 16:11











  • if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW_PROJECT_DIR" != "" ]; then echo $CMD_PRO_NAME_VAL echo "$CMD_PRO_NAME_VAL"|sed 's#/##g'

    – Hiranya Kavishani
    Nov 15 '18 at 16:12












  • here $CMD_PRO_NAME_VAL = test/ and echo "$CMD_PRO_NAME_VAL"|sed 's#/##g' I got it as "test". I want to take it to variable and print

    – Hiranya Kavishani
    Nov 15 '18 at 16:13












  • @chepner yes.how should I fix it?

    – Hiranya Kavishani
    Nov 15 '18 at 16:21







1




1





Your Bash syntax is all wrong. Please post the actual commands you're running.

– ruakh
Nov 15 '18 at 16:09





Your Bash syntax is all wrong. Please post the actual commands you're running.

– ruakh
Nov 15 '18 at 16:09













You are getting what appears to be an error message in trying to run test/ as a command, not the contents of PRO_VAL (which remains empty, so the "output" of echo $PRO_VAL appears after the error message. sed never actually produces any output, as it had no input.)

– chepner
Nov 15 '18 at 16:11





You are getting what appears to be an error message in trying to run test/ as a command, not the contents of PRO_VAL (which remains empty, so the "output" of echo $PRO_VAL appears after the error message. sed never actually produces any output, as it had no input.)

– chepner
Nov 15 '18 at 16:11













if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW_PROJECT_DIR" != "" ]; then echo $CMD_PRO_NAME_VAL echo "$CMD_PRO_NAME_VAL"|sed 's#/##g'

– Hiranya Kavishani
Nov 15 '18 at 16:12






if [ "$IS_BUILD_COMMAND" = true ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW_PROJECT_DIR" != "" ]; then echo $CMD_PRO_NAME_VAL echo "$CMD_PRO_NAME_VAL"|sed 's#/##g'

– Hiranya Kavishani
Nov 15 '18 at 16:12














here $CMD_PRO_NAME_VAL = test/ and echo "$CMD_PRO_NAME_VAL"|sed 's#/##g' I got it as "test". I want to take it to variable and print

– Hiranya Kavishani
Nov 15 '18 at 16:13






here $CMD_PRO_NAME_VAL = test/ and echo "$CMD_PRO_NAME_VAL"|sed 's#/##g' I got it as "test". I want to take it to variable and print

– Hiranya Kavishani
Nov 15 '18 at 16:13














@chepner yes.how should I fix it?

– Hiranya Kavishani
Nov 15 '18 at 16:21





@chepner yes.how should I fix it?

– Hiranya Kavishani
Nov 15 '18 at 16:21












2 Answers
2






active

oldest

votes


















0














PRO_VAL=$(echo $CMD_VAL|sed 's#/##g')


you need to echo first, "$CMD_VAL"|sed 's#/##g" will be run $CMD_VAL and pipe to sed,it's not correct.






share|improve this answer























  • Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

    – Gordon Davisson
    Nov 15 '18 at 18:51


















4














No need to spawn an external process. c.f. this cheat-sheet for a guide on things like using the interpreter's built-in string processing tools.



$: CMD_VAL='test/' # no spaces...
$: CMD_VAL=$CMD_VAL%/ # strip the training slash
$: echo "$CMD_VAL"
test





share|improve this answer


















  • 1





    Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

    – Gordon Davisson
    Nov 15 '18 at 18:55











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323420%2freplace-slash-in-to-empty-in-bash%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














PRO_VAL=$(echo $CMD_VAL|sed 's#/##g')


you need to echo first, "$CMD_VAL"|sed 's#/##g" will be run $CMD_VAL and pipe to sed,it's not correct.






share|improve this answer























  • Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

    – Gordon Davisson
    Nov 15 '18 at 18:51















0














PRO_VAL=$(echo $CMD_VAL|sed 's#/##g')


you need to echo first, "$CMD_VAL"|sed 's#/##g" will be run $CMD_VAL and pipe to sed,it's not correct.






share|improve this answer























  • Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

    – Gordon Davisson
    Nov 15 '18 at 18:51













0












0








0







PRO_VAL=$(echo $CMD_VAL|sed 's#/##g')


you need to echo first, "$CMD_VAL"|sed 's#/##g" will be run $CMD_VAL and pipe to sed,it's not correct.






share|improve this answer













PRO_VAL=$(echo $CMD_VAL|sed 's#/##g')


you need to echo first, "$CMD_VAL"|sed 's#/##g" will be run $CMD_VAL and pipe to sed,it's not correct.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 16:14









3h1Nh7YX243h1Nh7YX24

312




312












  • Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

    – Gordon Davisson
    Nov 15 '18 at 18:51

















  • Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

    – Gordon Davisson
    Nov 15 '18 at 18:51
















Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

– Gordon Davisson
Nov 15 '18 at 18:51





Please always double-quote variable references (e.g. echo "$CMD_VAL"), to prevent weird parsing under some circumstances.

– Gordon Davisson
Nov 15 '18 at 18:51













4














No need to spawn an external process. c.f. this cheat-sheet for a guide on things like using the interpreter's built-in string processing tools.



$: CMD_VAL='test/' # no spaces...
$: CMD_VAL=$CMD_VAL%/ # strip the training slash
$: echo "$CMD_VAL"
test





share|improve this answer


















  • 1





    Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

    – Gordon Davisson
    Nov 15 '18 at 18:55















4














No need to spawn an external process. c.f. this cheat-sheet for a guide on things like using the interpreter's built-in string processing tools.



$: CMD_VAL='test/' # no spaces...
$: CMD_VAL=$CMD_VAL%/ # strip the training slash
$: echo "$CMD_VAL"
test





share|improve this answer


















  • 1





    Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

    – Gordon Davisson
    Nov 15 '18 at 18:55













4












4








4







No need to spawn an external process. c.f. this cheat-sheet for a guide on things like using the interpreter's built-in string processing tools.



$: CMD_VAL='test/' # no spaces...
$: CMD_VAL=$CMD_VAL%/ # strip the training slash
$: echo "$CMD_VAL"
test





share|improve this answer













No need to spawn an external process. c.f. this cheat-sheet for a guide on things like using the interpreter's built-in string processing tools.



$: CMD_VAL='test/' # no spaces...
$: CMD_VAL=$CMD_VAL%/ # strip the training slash
$: echo "$CMD_VAL"
test






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 16:15









Paul HodgesPaul Hodges

4,0711524




4,0711524







  • 1





    Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

    – Gordon Davisson
    Nov 15 '18 at 18:55












  • 1





    Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

    – Gordon Davisson
    Nov 15 '18 at 18:55







1




1





Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

– Gordon Davisson
Nov 15 '18 at 18:55





Removing all slashes is more complicated, but can be done: "$CMD_VAL////". To explain it: the first // means "replace all occurrences of", then / is an escaped forward slash (escaped since / would otherwise be a delimiter), then / is the delimiter between the pattern and its replacement, and then there's a blank replacement string. Whee!

– Gordon Davisson
Nov 15 '18 at 18:55

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323420%2freplace-slash-in-to-empty-in-bash%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus