Questions tagged [arguments]
An argument is usually defined as the actual value passed to a function, procedure, or command line program.
514
questions
1
vote
1
answer
44
views
Is there a way to make a comment after a "\" has been used to split a shell command onto differemt lines? [duplicate]
I am using arch and bash. Everything is up to date.
I have this command which works just fine
yad \
--timeout=2 \
--undecorated \
--posx=1200 --posy=633 \
--title=" " \
--window-icon='/home/$...
0
votes
1
answer
32
views
How can I pass $@ to exec.args of Maven?
things I tried in my script run.sh:
mvn exec:java -Dexec.mainClass=my.App -Dexec.args="$@"
mvn exec:java -Dexec.mainClass=my.App -Dexec.args=$@
when I call the script like:
./run.sh arg1 ...
0
votes
1
answer
60
views
Bash script with command line options gets stuck and doesn't set default values for variables
I am pretty green when it comes to bash scripts and completely new to command line functionality in bash. I tried my hand at a script which is supposed to be useable both with command line arguments ...
8
votes
1
answer
649
views
Looking for a more permissive alternative to GNU getopt for wrapper script
I often find myself writing shell functions or shell scripts that are meant to be wrappers around other commands.
It is also frequent that I want such a wrapper to support a few flags/options. The ...
0
votes
1
answer
63
views
Can find reliably call itself from -exec without breaking the semantics of the two instances?
Following http://superuser.com/questions/1780479 and http://superuser.com/questions/1777606, we issue the following script to compare times of the same–full-path symlinks under directories $1 and $2:
#...
0
votes
3
answers
127
views
grep exact process name in bash script with variable argument
I'm writing a bash script where I want to grep the name of a process. This name is the argument when the script is executed.
Normally I can do this ps -ef | grep [w]ord to get the correct processes.
...
0
votes
1
answer
218
views
Run multiple instances of a script, with arguments, in parallel invironments
I have a script that connects to Openshift and launches a series of commands on PODs.
Since I am working with multiple PaaS, I need to launch the script on each of them with a different connection ...
9
votes
1
answer
981
views
What does a hyphen do next to the argument position in bash shell script? Like ${1-}
I've come across this piece of code from here:
#!/bin/bash
# ...
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo "Usage..."
exit
fi
I understand what this does is print the ...
0
votes
1
answer
28
views
function that allows different outputs dependent on argument values
With the following function I want to be able to call it
with nico-usage or with a numeric value to print a different string.
Con this be cleaned up or made easier.
nico-usage ()
{
local ...
0
votes
2
answers
335
views
gnome-terminal how to send commands
For an application, I need to open a new terminal window and later execute some commands in that.
I tried the command
gnome-terminal
And it works properly, it open a new terminal, but when i want to ...
0
votes
3
answers
436
views
Parsing multiple arguments into a bash script
I've tried a few solutions posted here, but to no avail. I'm hoping it's something silly and obvious that I've missed, that you can spot easily, and I can facepalm myself.
I have a bash script ...
0
votes
0
answers
17
views
How to get the second and later arguments in a bash command? [duplicate]
I know I can use "$@" to get or pass all of the arguments.
However, I'm creating a small utility script to encapsulate HTTPie command.
Here's my code, inside Post file:
#!/bin/bash
clear
...
0
votes
1
answer
212
views
/bin/sh string variable as multiple argument
I have a docker container setting an ARG to
CMAKE_ARGS=-DWITH_CPU=arm -DCMAKE_C_FLAGS="-march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -mvectorize-with-neon-quad" -DCMAKE_CXX_FLAGS="-...
0
votes
1
answer
60
views
Complete a positional argument only once
I'm trying to write a completion for a command (call it gs) that takes an SSH hostname as its first argument, and an arbitrary string as the second argument.
I've stolen this from the default SSH ...
10
votes
1
answer
990
views
Space not taken as an argument separator by shell script (could someone please explain that small file difference ?)
SHORT VERSION (TL;DR)
I have 2 small one-line files, seemingly identical :
$ cat f1 f2
./cconv.sh 100 EUR USD
./cconv.sh 100 EUR USD
But they are not, there is a 1 byte difference in size :
$ ls -l ...
2
votes
4
answers
385
views
Empty string breaks command line
I am having trouble trying to describe my issue. Please bear with me. I have a script that calls a command. I need to optionally include an extra argument in the command line depending on the input ...
1
vote
1
answer
81
views
How to pass URL string in .desktop file in quotes
I installed WhatsApp Desktop via Wine and I am trying to associate whatsapp:// links with it.
Executing the following via command line works and starts a chat with the phone number +1234567890:
env ...
1
vote
1
answer
84
views
Determining name of the variable passed to function
If I pass variable as a positional argument to a function, is it possible to determine the name of the variable used from inside the function, or I can only access its value?
I have a function envir-...
0
votes
1
answer
251
views
Environment variable and function argument [closed]
I have a collection of bash functions that include a verbosity level option. According to the set value, different levels of outputs are generated. The verbosity is local to each function.
But I ...
2
votes
1
answer
4k
views
How to mix plain arguments with flagged arguments in bash scripting?
for instance, gcc accepts the input file without any flag and the output file with the -o flag in:
gcc input.c -o output.out
or
gcc -o output.out input.c
I am creating a random password generator bash ...
-1
votes
1
answer
58
views
How can I apply enscript to upwards of 60k files?
I want to apply Gnu enscript on a large collection of files (every file tracked by git in the current Linux kernel). I have just for the hell of it. However, I've tried various things to pass those ...
0
votes
2
answers
57
views
Bash use arguments returned from subshell in current shell
Sorry if the title is bad (it is already the best one I can think of).
Anyway, here is the line of code:
printf "%s\n" "$(echo a b "c d")
Simple code. Of course, I will ...
2
votes
1
answer
644
views
Systemd service prefix on ExecStart=@/path/to/executable doesn't change the `argv[0]`
According to the manual man systemd.service using the prefix @ says this:
If the executable path is prefixed with "@", the second specified
token will be passed as "argv[0]" to ...
2
votes
3
answers
183
views
Why do I need eval in this example?
I'm exploring the notion of having a shell script input and output two dimensional structures of strings, with the limitation that the strings do not contain newlines. They can contain spaces.
The way ...
0
votes
0
answers
8
views
Regex command line argument is expanded [duplicate]
I am trying to pass a regex pattern as an argument to my script as follows:
bash script.sh '[a-z]*[0-9]*'
in my script I am assigning it to a variable
FIRST_ARG=$1
using echo $FIRST_ARG results in ...
1
vote
2
answers
280
views
GNU Parallel with named arguments
I have the following command in my Makefile
parallel \
--eta \
--bar \
--joblog mnist/embedder.joblog \
pipenv run python3 \
-m mnist.train_embedder \
--...
1
vote
2
answers
210
views
identify if present and remove specific argument from shell args
I have to check if particular argument lets say 'java8' is present in my shell arguments to script and if it is present remove it . Also I want it to be stored in some other variable , but want it to ...
1
vote
0
answers
121
views
How Can I Add Short Arguments to a Shell Script
To add options, I have the following in one of my scripts:
parse_opts() {
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
help=1
shift
;;
-r|--...
1
vote
3
answers
192
views
What is the difference in how linux implements commands which accept input via pipe vs. command arguments?
Although there are many similar questions, I cannot find one that directly answers my question. I understand the basics of OS memory management, processes, communication between processes, etc. ...
0
votes
2
answers
74
views
Expanding an argument within single quotes
I'm trying to create a function that executes the following
composer config repositories.foo '{"type": "path", "url": "/b/foo-bundle"}'
I'm starting with
lb() { ...
1
vote
1
answer
2k
views
Call a command from a shell script, passing most arguments, allowing arguments with blanks
I am have a wrapper run_sas.sh around a command sas that runs SAS code in batch. A typical call looks like this
./run_sas.sh -sysin /my_code/my_program.sas -log /my_log_folder/my_program.log
run_sas....
0
votes
1
answer
236
views
unable to print a positional parameter in a script
I'm using this method to open a Gnome terminal window and run command(s) — in this case, to send me simple notification messages (will be scheduled via at):
#!/bin/sh
gnome-terminal -- /bin/sh -c '...
1
vote
2
answers
114
views
What is the colon in postgres' process command-lines?
For example Postgres process command-lines are like
postgres 794 1 0 Nov06 ? 00:00:03 /usr/pgsql-9.3/bin/postgres -D /var/lib/pgsql/9.3/data -p 5432
postgres 857 794 0 Nov06 ? ...
0
votes
0
answers
154
views
How can I modify this script so that I can add multiple users by providing arguments?
How can I modify this script so that I can add multiple users by providing arguments (usernames) in the command line instead?
I know at the very least I need to remove the read options. I don't want ...
0
votes
1
answer
513
views
Get argument position given its value in a bash script
How can I get the position of an argument by using its value?
For example:
myScript.sh hello world
echo "$1"
hello
How can I get the position of 'hello', which is 1 in this case?
0
votes
1
answer
43
views
How to provide condition to the parameter
While providing external parameter values should have before and after hyphen. If hyphen is not there it should reflect the error stating that the hyphen should be needed before and after the text.
...
2
votes
3
answers
191
views
How to pass argument to a for loop from a file and run in parallel, and create log for each argument
for test in "${a[@]}"
do
sh ansiblescript.sh -s $a
if [[ $? -eq 0 ]]; then
echo "Success"
else
echo "Failed"
exit 1
fi
done
...
0
votes
1
answer
66
views
Find with optional parenthesised arguments
How to add optional grouped argument lists to find?
For example, using an array of base arguments that define files that will always be found, no matter what other variable conditions are specified.
# ...
0
votes
1
answer
410
views
Assign default var if no argument, otherwise treat var like its not there?
I've got a sync script that runs a few rsync and rclone commands. I'd like to add an easy way to run the script in dry mode by default by passing the '-n' switch. I'm running into an issue with this ...
1
vote
0
answers
241
views
Capture arguments after PIPE in a bash script as string
I am writing a simple script (well, I thought it would be simple) to gather and log a 'reason' for using sudo. That part is working pretty straightforward based on another article I found (https://...
0
votes
0
answers
52
views
Secure transfer of arguments to a program (dash/bash)
Transfer via stdin
#!/bin/dash
echo 'password' | program -
Transfer via stdin using an intermediate variable
var_pass=$(echo 'password')
echo $var_pass | program -
unset var_pass
Transfer via ...
1
vote
1
answer
437
views
Help understanding Bash command-line argument parsing code
I want to take two arguments and a third optional one for a script I am developing. I am new working with bash so I have been copying and trying to understand the following code that does what I want (...
-1
votes
3
answers
986
views
Parse comma- and colon-separated numbers into to array values in Bash script
I have a Bash script for deploying a service. It needs an update in the form of an additional command line argument for specifying ports for launching multiple instances of the service. The argument ...
0
votes
3
answers
2k
views
How to run all command line arguments via another shell?
I have a script tempenv which I'd like to use as follows:
$ tempenv ls -l
tempenv looks like this:
#!/bin/bash
setarch ... /bin/bash -c $@
However, it doesn't work as I intend. Instead, it only ...
3
votes
1
answer
2k
views
What does crontab do when I give no argument?
I accidentally typed this command without any arguments and hit enter, and it seems the terminal is running something, so my question is what crontab do when I give no arguments?
[root@localhost ~]# ...
-2
votes
1
answer
481
views
Checking for numeric arguments
I want to check function arguments, and check whether $2 and $3 are numeric
Is the following line the way to use the AND statement? Am I using = the correct way to check for numeric digits?
if [[ &...
2
votes
2
answers
8k
views
How to check arguments given to a bash script efficiently?
I wrote a bash script but since I'm a self-learner bash rookie, I wanted to ask if I can check the given arguments more efficiently. I also googled about this and checked topics here but the examples ...
0
votes
2
answers
641
views
How to properly parse a quoted arg-list string in a shell script?
Summary
How to convert a single string a "b" 'c d' $'e\nf' into separate arguments, respecting quotes and preserving whitespaces and newlines?
Question
I'm trying to read and process the ...
2
votes
2
answers
419
views
AWK Command Argument Error
I have a dataset which contains contact information of students, the sample data set is as follows
First Name, Last Name, Address, Phone Number
John, Doe, "House # 11, Street xyz, Road, Area"...
0
votes
1
answer
459
views
passing arguments inside quote, e.g. screen -dm ' ls /home/$dir1 '
I use the following script
#!/bin/bash
echo 'Please enter the password of your XXXX:'
read -sp 'Password:' password
screen -dm bash -c ' BLABLA '
Problem is that my commands in BLABLA include the ...