The first argument ($1) was in some format I don't remember that was taken using awk. The milliseconds argument was parsed as 009, for 9 milliseconds. However, bash treats numbers starting with a leading 0 as octal, so I converted them to decimal. It's not exactly using #$, but when I looked at this code after a while and tried to remember what was going on, I thought that was an expression at first and found this question, so this might help someone else.
In bash this is generally a comment, everything after the hash (on the same line) is ignored.
However, if your bash script is being passed to something unusual it could be interpreted by that.
For instance, if you submit a script to the Sun Grid Engine:
"Any line beginning with hash-dollar, i.e., #$, is a special comment which is understood by SGE to specify something about how or where the job is run. In this case we specify the directory in which the job is to be run (#$ -cwd) and the queue which the job will join (#$ -q serial.q)." (source: http://talby.rcs.manchester.ac.uk/~rcs/_linux_and_hpc_lib/sge_intro.html)
I just came across a #$ in a script and was wondering the same thing. There is answer which was not mentioned yet: In bash search and replace (see here).
Normally, it works like this:
${PARAMETER/PATTERN/STRING}
PATTERN can also include anchors, to match it either at the beginning or the end; namely # and %:
One place where you might see
#$
come up is inside a arithmetic expression when changing base: http://www.gnu.org/software/bash/manual/bashref.html#Shell-ArithmeticFor example
echo $((2#101))
will convert101
to base two, and print5
.I recently used this here:
The first argument (
$1
) was in some format I don't remember that was taken usingawk
. The milliseconds argument was parsed as009
, for 9 milliseconds. However, bash treats numbers starting with a leading 0 as octal, so I converted them to decimal. It's not exactly using#$
, but when I looked at this code after a while and tried to remember what was going on, I thought that was an expression at first and found this question, so this might help someone else.#$
does "nothing", as#
is starting comment and everything behind it on the same line is ignored (with the notable exception of the "shebang").$#
, as you had it, prints the number of arguments passed to a shell script (like$*
prints all arguments).In bash this is generally a comment, everything after the hash (on the same line) is ignored. However, if your bash script is being passed to something unusual it could be interpreted by that.
For instance, if you submit a script to the Sun Grid Engine: "Any line beginning with hash-dollar, i.e., #$, is a special comment which is understood by SGE to specify something about how or where the job is run. In this case we specify the directory in which the job is to be run (#$ -cwd) and the queue which the job will join (#$ -q serial.q)." (source: http://talby.rcs.manchester.ac.uk/~rcs/_linux_and_hpc_lib/sge_intro.html)
I just came across a
#$
in a script and was wondering the same thing. There is answer which was not mentioned yet: In bash search and replace (see here).Normally, it works like this:
PATTERN
can also include anchors, to match it either at the beginning or the end; namely#
and%
:You can also use a variable for
PATTERN
- and skip the slashes to add to the confusion (and replace the pattern match with an empty string):And here it is, a
#$
in a bash string.It could be possible that the intended expression was $# instead of #$
$# Stores the number of command-line arguments that were passed to the shell program.
for example:
Displays the message stored in the $USAGE variable if the number of command-line arguments is 0.