I'm currently working on a script that uses curl's to check internet connectivity with and without a proxy being specified.
Basically what I'd like to achieve is having the script output fail or success according to the "method" used (direct or via proxy).
A very ugly way of doing it:
The script expects 2x arguments. The first one is the URL and the second one is the proxy address.
Whats a more dynamic way of writing that ugly if statement?
I didnt request the whole code, just the first commented line.
Anyway, thanks.
First and foremost, both "${2:-}" are useless, as that would fill an empty variable with... emptyness.
Second, you dont want something in a variable that defines an extra option - if it hasnt been set by the user.
I'll keep the short approach you've had in the first post:
hth & hf
Last edited by sea; 03-12-2020 at 03:10 PM..
Reason: typo
One question though regarding the following piece of code:
Why not do a proper if/else statement here?
It's shorter and i'm lazy.
Also it only 'contains' 1 task per situation, so this is enough.
However, if there are more lines to be made for each situation, i'd go with a proper if/else statement as well.
Quote:
Originally Posted by da1
I did that because of the "set -u". What would be the right approach?
Ok, can you elabortate on that? Why is it wrong (?) to append a string to a variable?
If you want to check wether a variable exists (or has content) or not (empty) and DECIDE what to execute according to that, it's a bad choice to fill the variables anway.
One usualy uses this to make sure a REQUIRED variable gets it's DEFAULT or FALLBACK values, as in:
I have.. uhm.. misspelled.. my... uhm.. concern... in the previous post, because: ${1:-} doesnt actualy do something, and is basicly the same as ${1}, but it (the first one) indicates that you wanted to put some variable there, which then might interfere.
Also, by setting a string to an empty variable, you'd say the script to ALWAYS use '$proxy', because '$proxy' would contain something. (well, not in your actual code, that's just bad syntax)
The set -u only requires you to declare the variable before invoking it.
So any of these are valid options for that case/command:
Quote:
declare var
local var
var=""
hth
--- Post updated at 21:54 ---
On a further note, your exit codes in those functions just exit the fuction, therefor return could be used there.
For example, try this:
And then change the return number.
Hello :
I want to make a netfilter conntrack module for myself. So I copy all the source code about netfilter conntrack from kernel source tree to my external directory. It can be insmod after compiled. Then I add some members to the struct nf_conn, and it 's compiled successfully. However, it... (1 Reply)
After a bash function is run the below file is produced:
out_name.txt tab-delimeted
Input Errors and warnings AccNo Genesymbol Variant Reference Sequence Start Descr. Coding DNA Descr. Protein Descr. GeneSymbol Coding DNA Descr. GeneSymbol Protein Descr. Genomic... (3 Replies)
Hi
In one of the script I am seeing some thing like exit 7,exit 1,exit 2,exit 3,exit 9,exit6.What is the difference between all of this exit.Can anyone help here please (3 Replies)
Hey, all!
Why is the "human readable" flag changing the behavior of du? And while I'm at it, can you make du only look at files, not directories. I often find myself wanting to find the largest file(s) in a dir or vol. Using 'find' itself, it seems you have to at least be able to guess the size of... (2 Replies)
Hello all,
I need to print all the lines before a specific string and print a custom message 2 lines after that.
So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message.
My code thus far is:... (4 Replies)
Hi,
I would like to know if there's any option to use with the du command so that I can list only the files/directories on the current filesystem... I usually use
du -gs *But I'd like to see only the directories in the filesystem I am on, and not the mount point directory of other fss...
... (6 Replies)
Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max
But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
#!/bin/ksh
application task run command //returns 0 if successful
if ; then echo "Ran Fine"
else echo "Didnt run"
fi
When I run the script, here is the output
Status code = 0
ksh: [0: not found.
Job didnt run
any suggestions? (4 Replies)
I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)