mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2280 (markdown)
26
SC2280.md
Normal file
26
SC2280.md
Normal file
@@ -0,0 +1,26 @@
|
||||
## $0 can't be assigned this way, and there is no portable alternative.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
#!/bin/sh
|
||||
$0=myname
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
`$0` can not be changed in a portable way.
|
||||
|
||||
### Rationale:
|
||||
|
||||
You appear to be trying to assign a new value to `$0` in a `sh` script.
|
||||
|
||||
There is no portable way to do this. Write around it, or switch to Bash.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
If you instead wanted to compare the value of `$0`, use a comparison like `[ "$0" = "myname" ]`.
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user