This question already has answers here:
What are the special dollar sign shell variables?
(4 answers)
Closed 8 years ago.
I am trying to understand a script that was written a few years ago by someone that is no longer available here. The script references $? a few times. What is this?
P.S. Google couldn't help since it seems to strip the $? from the search term
You really should read the GNU bash manual. $? is a special parameter which
expands to the exit status of the most recently executed foreground pipeline.
Read also the advanced bash scripting guide.
Related
This question already has answers here:
Difference between ${} and $() in Bash [duplicate]
(3 answers)
Brackets ${}, $(), $[] difference and usage in bash
(1 answer)
Closed 6 months ago.
This post was edited and submitted for review 6 months ago and failed to reopen the post:
Original close reason(s) were not resolved
In the bash shell,
$ date +%Y%m%d%H%M
202208161535
So I put it in a bash script
#!/bin/bash
dat=${date +%Y%m%d%H%M}
echo "dat=" ${dat}
But when I run it, I get
$ test.bash
./test.bash: line 2: ${date +%Y%m%d%H%M}: bad substitution
dat=
How should I do it?
ADD
I found
dat=`date +%Y%m%d%H%M`
works. But I'm curious how I can do it with dat = ${data +%Y%m%d%H%M}.
ADD2
This question arose because of the mistake, or rather from not knowing the difference of ( ) and { }. Those who cannot notice this difference cannot search with search pattern 'difference of ( ) and { } in bash'. So the referenced links 'supposed to have solution for this question' cannot be searchable by the people like me. So I think this question is worth being kept as is.
#!/bin/bash
dat=`date +%Y%m%d%H%M`
echo "dat="${dat}
The above code is working code
This question already has answers here:
Why do you need to put #!/bin/bash at the beginning of a script file?
(10 answers)
What is the preferred Bash shebang ("#!")?
(6 answers)
Closed 4 years ago.
What is the significant of using #!/bin/bash in the starting of bash script? Can we write a bash script without #!/bin/bash ?
This line is called shebang. It’s a ‚magic‘ line telling the program loader (kernel) how to execute a script on unixoid systems.
Cf. https://en.m.wikipedia.org/wiki/Shebang_(Unix)
This question already has answers here:
How does the #! shebang work?
(3 answers)
Closed 5 years ago.
while following this tutorial I found a command
#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
I don't understand the meaning of #!/bin/sh. I tried to search it but google removes the ! symbol from search results.
What does #!/bin/sh mean here?
Please help.
#! specifies the program with which the script should be executed if you not explicitly call it which any
in your case, if you call your script with: <scriptname.sh> Linux will execute it as /bin/sh <scriptname.sh>
This question already has answers here:
What are the special dollar sign shell variables?
(4 answers)
Closed 6 years ago.
I have some bash shell script code
#!/bin/bash
var=""
something happens here
var=$!
I could't find anyting about it and I'm not sure if it makes any sense but if so - what does it mean?
Thanks.
EDIT: Wow - looks like I didn't search deep enough - the answer lies hier What are the special dollar sign shell variables?
$! resolves to the process id of the latest process run in the background.
This question already has answers here:
Trouble understanding parameter substitution in a script
(1 answer)
Usage of :- (colon dash) in bash
(2 answers)
Closed 9 years ago.
I've found this in a shell script that I use and I'm having trouble finding a formal description/definition of this syntax:
ACTION=${1:-update}
I'm assuming that if $1 variable does not exist (no command line arguments) then "-update" is used.
It's not esoteric. It's POSIX, and even Bourne. In every shell manpage ever. man bash or man ksh. The assumption is mostly right, if the parameter 1 is unset or empty string, then expand the alternate.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02