From 8318e0ea2f3633554918562881f4fd46675340dd Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 30 Dec 2020 20:13:53 -0800 Subject: [PATCH] Created SC2280 (markdown) --- SC2280.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 SC2280.md diff --git a/SC2280.md b/SC2280.md new file mode 100644 index 0000000..5e822ed --- /dev/null +++ b/SC2280.md @@ -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! \ No newline at end of file