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