D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

[LUG]Re: trivial shell script - reinvented 16 years later

 

I didn't know of those functions.
Never covered, as far as I remember, as I lunged to learn unix user
environment back in the mid-late 1990's.

The value of a peer group to be mentored into the power of the unix
philosophy...


A
* run of shell commands...
* "got it" with own versions of "true" and "false"?
* "mytrue.sh" and "myfalse.sh" tested in the shell
* some more trying shell commands

bash-3.2$ false
bash-3.2$ true
bash-3.2$ if true; then echo y; else echo n; fi
y
bash-3.2$ if false; then echo y; else echo n; fi
n


"mytrue.sh":
#!/bin/sh
exit 0

"myfalse.sh":
#!/bin/sh
exit 1


bash-3.2$ if ./mytrue.sh; then echo y; else echo n; fi
y
bash-3.2$ if ./myfalse.sh; then echo y; else echo n; fi
n


bash-3.2$ if (true&&false); then echo y; else echo n; fi
n
bash-3.2$ if (true||false); then echo y; else echo n; fi
y

* Bit more reading => learned about shell "?" variable

bash-3.2$ true; echo $?
0
bash-3.2$ false; echo $?
1

Been a delight to wake up to finding this.
The unix way of thinking is rewarding.

Best wishes,
Rich Smith



> On 19 Oct 2023, at 00:55, Simon Waters <simon@xxxxxxxxxxxxxx> wrote:
> 
> Call that a trivial shell script. 
> 
> I have seen /bin/false implemented as a Bourne shell script.
> 
> The implementation is left as an exercise to the reader.
> 
> 
> -- 
> The Mailing List for the Devon & Cornwall LUG
> FAQ: https://www.dcglug.org.uk/faq/

-- 
The Mailing List for the Devon & Cornwall LUG
FAQ: https://www.dcglug.org.uk/faq/