mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2277 (markdown)
29
SC2277.md
Normal file
29
SC2277.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
## Use BASH_ARGV0 to assign to $0 in bash (or use [ ] to compare).
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/bin/bash
|
||||||
|
$0=myscriptname
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/bin/bash
|
||||||
|
BASH_ARGV0=myscriptname
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
You appear to be trying to assign a new value to `$0` in a Bash script. To do this, instead assign to the special variable `BASH_ARGV0`.
|
||||||
|
|
||||||
|
If you instead wanted to compare the value of `$0`, use a comparison like `[ "$0" = "myname" ]`.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user