Home > Software design >  Bash Script Path Containing Space
Bash Script Path Containing Space

Time:10-01

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.

CodePudding user response:

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
  •  Tags:  
  • bash
  • Related