You need to use single quotes to prevent interpolation happening in your calling shell.
$ bash -c 'echo arg 0: $0, arg 1: $1' arg1 arg2
arg 0: arg1, arg 1: arg2
Or escape the variables in your double-quoted string. Which to use might depend on exactly what you want to put in your snippet of code.
Related Contents:
- Indirect variable assignment in bash
- Lookup shell variables by name, indirectly [duplicate]
- How to modify a global variable within a function in bash?
- Are shell scripts sensitive to encoding and line endings?
- In the shell, what does ” 2>&1 ” mean?
- How to loop through file names returned by find?
- ‘\r’: command not found – .bashrc / .bash_profile [duplicate]
- Shell script read missing last line
- How to use a variable’s value as another variable’s name in bash [duplicate]
- How to run the sftp command with a password from Bash script?
- Remove a fixed prefix/suffix from a string in Bash
- Return value in a Bash function
- How to pipe input to a Bash while loop and preserve variables after loop ends
- Checking the success of a command in a bash `if [ .. ]` statement
- Assignment of variables with space after the (=) sign?
- Check number of arguments passed to a Bash script
- Capturing Groups From a Grep RegEx
- YYYY-MM-DD format date in shell script
- How can I exclude all “permission denied” messages from “find”?
- Bash script and /bin/bash^M: bad interpreter: No such file or directory [duplicate]
- Listing only directories using ls in Bash?
- Bash expand variable in a variable
- How to recursively find the latest modified file in a directory?
- How to suppress Terminated message after killing in bash?
- Bash script compare two date variables [duplicate]
- How to extract one column of a csv file
- How to add to the end of lines containing a pattern with sed or awk?
- “Invalid Arithmetic Operator” when doing floating-point math in bash
- Passing a string with spaces as a function argument in Bash
- Why can’t I use job control in a bash script?
- Bash script – store stderr in a variable [duplicate]
- Trying to split a string into two variables
- Send string to stdin
- How to rename with prefix/suffix?
- Specify other flags in awk script header
- How do I prompt a user for confirmation in bash script? [duplicate]
- bash: $[] vs. $(())
- Sleep until a specific time/date
- How to enter ssh password using bash? [duplicate]
- Exit when one process in pipe fails
- error while running “source .vimrc”
- How to limit number of threads/sub-processes used in a function in bash
- Command to escape a string in bash
- Get the newest directory to a variable in Bash
- osascript using bash variable with a space
- Divide two variables in bash
- Forking / Multi-Threaded Processes | Bash
- How to use a bash script variable with sed [duplicate]
- Multiple commands in an alias for bash
- How do I kill a backgrounded/detached ssh session?