0

I just have this simple script :

#!/bin/bash

mainDir="EVE-NG\ Repos"
mega-ls [email protected]:$mainDir

But I got this error :

[API:err: 08:40:34] Couldn't find "[email protected]:EVE-NG\ Repos"

When I enter the command natively in bash like this :

mega-ls [email protected]:EVE-NG\ Repos

It works, but inside the script, it doesn't.

3
  • 2
    Remove the `\` from the variable assignment, and quot your variables, try pasting your code at shellcheck.net for validation/recommendation. Commented Sep 30, 2021 at 8:46
  • I tried to remove it, but the path has to be passed to mega-ls as (EVE-NG\ Repos) in order to work. I tried the followings : mainDir = "EVE-NG\\ Repos" mainDir = "EVE-NG\ Repos" None of them works Commented Sep 30, 2021 at 8:50
  • 1
    The script and the command entered interactively are not equivalent: in the script, the backslash is literal. mainDir='EVE-NG Repos'; mega-ls [email protected]:"$mainDir" should really work. Commented Sep 30, 2021 at 9:05

1 Answer 1

1

Try typing this in at the shell:

mega-ls "[email protected]:EVE-NG Repos"

Does that clear things up? Inside quotes you don't need to escape spaces (and it doesn't work, sending \char instead).

Note that this is required all the way:

Myvar="this and that"
echo "$Myvar" #with quotes to get 1 arg
Sign up to request clarification or add additional context in comments.

Comments

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.