General TC > Programming & Scripting - Unofficial
Script to download extensions+dependencies on other Linux distros
GNUser:
Hi, Rich. Yes, using the integer syntax also fixes the error.
In your script you can use either the string comparison syntax:
[ "$var" = "string" ]
[ "$var" != "string" ]
Or the integer comparison syntax:
[ $var -eq 0 ]
[ $var -ne 0 ]
The reason you can use either in this script is because the $? variable will always be an integer (return code of the last command). Integers can be compared using integer comparison or string comparison (the shell implicitly converts integers to strings when performing a string comparison). The only thing that doesn't work is the == operator because, although it means the same thing as = in this context, it only exists in bash.
By the way, the integer comparisons would fail if the variable happens to hold a string (including empty string) or if the variable is undefined. For this reason, string comparison operators are generally preferable because they are less likely to error out. I generally only use integer comparison operators when I need one of these operators:
-gt (greater than)
-lt (less than)
-ge (greater than or equal to)
-le (less than or equal to)
Rich:
Hi GNUser
--- Quote from: GNUser on April 06, 2022, 09:02:52 PM ---Hi, Rich. Yes, using the integer syntax also fixes the error. ...
--- End quote ---
Thanks for confirming that.
--- Quote --- ... integer comparisons would fail if the variable happens to hold a string (including empty string) or if the variable is undefined. ...
--- End quote ---
If my intent is to compare integers, that's how I would want it to behave, because those are all bugs. I think I'll
stick to -eq and -ne for integers.
--- Quote from: GNUser on April 06, 2022, 04:01:48 PM --- ... It seems the two options are either to run the entire script as superuser or to change the three chown commands to sudo chown ...
--- End quote ---
I'm basically in agreement with you. That still leaves systems that request a password for sudo. That could include
systems that request a password for every sudo and those that use a timeout before requesting the password again.
For those situations I'm inclined to tell the user to run the script as root:
Forum error, please see attachment.
gadget42:
re: bash
reminded of recent:
https://rachelbythebay.com/w/2022/04/05/pipe/
and which referenced previous:
https://rachelbythebay.com/w/2013/08/01/script/
sharing is caring
gadget42:
one more(re: bash):
https://rachelbythebay.com/w/2022/04/06/text/
"running empty files"...successfully!?!
sharing is caring
GNUser:
Hi, Rich. I took the liberty to update the script with the following minor changes:
- Removed the == bashism
- Used integer comparison where appropriate (as per your preference)
- Added sudo handling
- Added UID user variable
The reason for adding the UID variable is that some TCL users (such as yours truly) use the user=somebody boot code (in my case it's user=bruno). So while user tc (UID 1001) does exist on my TCL box, my username on TCL is actually bruno (UID 1000). On my foreign Linux box my UID is also 1000. So for me, having the downloaded extensions owned by UID 1000 is much more convenient.
See attached.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version