You can do (without quotes during variable assignment):
a=~/Foo
cd "$a"
But in this case the variable $a
will not store ~/Foo
but the expanded form /home/user/Foo
. Or you could use eval
:
a="~/Foo"
eval cd "$a"
More Related Contents:
- How to concatenate string variables in Bash
- How do I iterate over a range of numbers defined by variables in Bash?
- Why should there be spaces around ‘[‘ and ‘]’ in Bash?
- Dynamic variable names in Bash
- How to escape single quotes within single quoted strings
- How to use double or single brackets, parentheses, curly braces
- When do we need curly braces around shell variables?
- Are double square brackets [[ ]] preferable over single square brackets [ ] in Bash?
- Brace expansion with variable? [duplicate]
- How to manually expand a special variable (ex: ~ tilde) in bash
- What is the benefit of using $() instead of backticks in shell scripts? [duplicate]
- Why equal to operator does not work if it is surrounded by space?
- What is the purpose of “&&” in a shell command?
- Bash syntax error: unexpected end of file
- Test for non-zero length string in Bash: [ -n “$var” ] or [ “$var” ]
- Why isn’t tilde (~) expanding inside double quotes? [duplicate]
- What is the meaning of the ${0##…} syntax with variable, braces and hash character in bash?
- Ternary operator (?:) in Bash
- Compound ‘if’ statements with multiple expressions in Bash
- Why source command doesn’t work with process substitution in bash 3.2?
- Using the && operator in an if statement
- How to escape history expansion exclamation mark ! inside a double quoted string?
- bash: $[] vs. $(())
- Commenting in a Bash script inside a multiline command
- osascript using bash variable with a space
- How to suppress variable substitution in bash heredocs
- Why equal to operator does not work if it is not surrounded by space?
- What does the curly-brace syntax ${var%.*} mean?
- Rsync syntax error when run from bash script
- What is the proper way to test a Bash function’s return value?