On lacking details, sorry. I'll attempt to be more concise and provide enough details so questions can be answered. The previous script posted was only an exersize used to help me understand how getopts works via hands on testing. I was not understanding how it worked after reading the man page and other sources of info. I'm not educated or work in anything related to Unix or Linux. I'm only an aspiring hobbyist Linux user with the goal of obtaining enough of a grasp on shell scripting to contribute something meaningful enough to be considered for use by others.
Add info:
linux 4.14.12-1
bash 4.4.012-2
gawk 4.2.0-2
sed 4.4-1
I currently have a wrapper script (see below), that is parsing options based on positional parameters only. The script is used to automate some tasks that can be performed manually, dealing with building and installing packages from pre made "PKGBUILD" build scripts.
As a learning exercise on getopts usage, at this point I'd like to build a "drop in replacement" using getopts, to replace the manual option parsing in my existing script. This makes it necessary to reprocess multiple letter options after getopts, per the example posted below.
After I get my head around getopts, etc, I'll likely need to completely rewrite the script as it seems getopts usage would pretty much dictate how a script is written, unless I'm missing something.
I have experimented with testing the $OPTARG variable, but it seems to create more issues to work around in my use case than just not using it. I decided instead to focus on using the package list provided by the double quoted $@ parameter after being processed by getopts.
Although my script does not currently handle multiple packages per run, I'd like to include this ability with the eventual proper implementation of getopts.
There are undoubtedly too many errors in the scripts below to discuss at this time. I'd prefer focusing on getting answers to following questions please, unless there is obviously something important that I am missing, (as in spaces being included as options). Thanks and I was not aware of that.
1) How to pass a variable from a script to a function? Is it possible?
2) Best way to get "Package List" contents into the function per below sample test script? I've tried many ways, unsuccessfully as below. The only method working so far is to write the parameter contents to a file, then read it in the function, per post #1 test script above. I could also use awk, etc to filter the variable parameters each time I need the packages in a function, but seems there has to be a more efficient method.
What I have so far for a "getopts drop in replacement" to replace the manual option parsing in script below.
Some test results of "getopts drop in replacement" above.
aurt script: Builds and installs AUR packages.
aurt-help script: Prints user info to screen.
Suggestions for learning more about shell scripting? I tend to learn more using a "hands on" approach than reading at this point. Most of the terse man pages and documentation I find, imply an underlying understanding of terminology and concepts, much of which I currently do not posess.
Thanks for any help.
Last edited by Cody Learner; 01-15-2018 at 03:03 PM..
Reason: spelling, format, misc corrections
Im running a script that runs scripts within it self and i need to pass vars made in the original script to scripts run within it and the only way i can think to do it is right the string to a file and read the file in the script (4 Replies)
Hi,
I am trying to sum up numbered columns and in order to tidy up the program I have wrote a function to do the adding of some numbers. I have a problem though with passing a variable to the function in the UNIX bash shell. The function only gives the first number in the variable list and does... (4 Replies)
Hi ,
I have three funcions f1, f2 and f3 .
f1 calls f2 and f2 calls f3 .
I have a global variable "period" which i want to pass to f3 .
Can i pass the variable directly in the definition of f3 ?
Pls help .
sars (4 Replies)
hello,
I got this error while I was trying to start some application in UNIX. It was an AIX 5.0 machine. It was not loading an .so file.Can anyone help me solving this issue...Its urgent please!!!!! (1 Reply)
Hello everyone,
I am curious to find a possible way of doing something like this in ksh:
call a function and have that function set the value of the variable that the function knows by the name of $1....
example:
#! /bin/ksh
set_var(){
case $1 in
var1) this is where I would like to... (7 Replies)
Hi All,
I am new to shell scripting required some help in passing the parameter value to the shell script.
I am writing a shell script, in the script I have created two functions as below.
first function
get_trend_ids () {
Here I am connecting to the database and getting all the... (3 Replies)
Hi all,
In the given script code .
I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob().
Any help?
Thanks
#!/bin/bash ... (55 Replies)
The objective of this function is to validate the file full path.
cat /dev/null > crontab_NOTEXISTS.txt
function File_Existence # Accepts 1 parameter
{
file_name="$(echo $1)"
echo "${file_name}"
&& break || echo "$file_name NOT FOUND" >> crontab_NOTEXISTS.txt
}
while read file_name... (7 Replies)
May i please know why is it printing the script name for $0 when i pass those parameters to function.
#!/bin/bash -x
usage()
{
echo "In Usage Function"
echo $0
echo $1
echo $2
}
echo "printing first time"
echo $0
echo $1
echo $2
usage $0 $1 $2
Output: (2 Replies)
Hello All,
I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and
put the variables in " ". Is there another way I can do this? Thank you in advance.
readtasklist() {
while read -r mod ver... (1 Reply)