Questions tagged [arguments]
An argument is usually defined as the actual value passed to a function, procedure, or command line program.
529 questions
3
votes
3
answers
903
views
How do I ensure a bash script argument is a specific value?
The following script is supposed to check $1 and see if it is a specific value. It only works when one Bash [[... =~ ...]] regex check is passed in an if statement.
The error is: When more than one ...
1
vote
4
answers
207
views
Need shell script help - processing the same option multiple times
So I've ran into a bit of a wall, I have an option in my script that calls a function which allows me to specify a file/directory and then I want to parse that output into a menu tool (using dmenu in ...
5
votes
4
answers
965
views
Pass multiple files as a single option
I'm trying to build a wrapper to execute a tool multiple times, then concatenate some of the results. I'd like to pass two sets of files to my wrapper script, then run the tool for each pair of files. ...
2
votes
0
answers
60
views
In the context of {ARG_MAX}, how robust is `find . -exec sh -c 'exec tool "$@" extra-arg' find-sh {} +`?
Suppose I want to do this:
find . -exec tool {} extra-arg +
It doesn't work and I know why: -exec … {} + does not allow extra-arg(s) between {} and +. So be it. It seems I can inject the extra-arg by ...
0
votes
1
answer
63
views
Can we pass directory list from find command as argument to another find command and execute md5sum?
I want to list all the directories in present directory and pass those directories as a argument to another find command
The below example will explain it correctly.
$ find . -maxdepth 1 -type d
.
./...
0
votes
1
answer
185
views
Manipulating arguments with OPTIND, OPTARG, getopts, and shift correctly
My small POSIX shell scripts do not usually take any arguments, so this is kind of new to me...
The minimal snippet would probably look like this:
# default for hotkey variable on top of script is set
...
0
votes
1
answer
73
views
getopt with several `--`
I have a script with this usage:
myscript [options] positional-args... -- [fwd-params]
Because [options] can have long, or short variants, I like using getopt. But I'm having troubles.
I use getopt ...
3
votes
1
answer
648
views
tcsh: Handle spaces in arguments when passing on to another command
I wrote a script that needs to call a command and pass on arguments. My script has its own parameters but some need to be passed through. This fails when arguments to my script have spaces in them.
...
0
votes
2
answers
157
views
Is it possible to use a command with an argument to trigger a bash alias?
I have a program that tries to trigger a screenlock using the following commands:
xdg-screensaver lock
xscreensaver -lock
cinnamon-screensaver-command --lock
The problem is that I'm using ...
2
votes
2
answers
701
views
bash: if $i equals any command line argument: if [[ " $@ " =~ " $i " ]]
To check if $i equals any command line argument (in a Bash script), I use
if [[ " $@ " =~ " $i " ]]
Is there a better way?
I mean, a way that is more recommendable, more general, ...
1
vote
1
answer
462
views
Bash parameter substitution with multi line error message
I'm using parameter substitution with an error message, such as ${var1:?'some message'}. I've incorporated a multi-line error message. Presently, it only functions properly when enclosed within single ...
1
vote
2
answers
220
views
Hide single argument from bash history
Is there a way to hide a single argument passed into the terminal, but still pass the argument to the command?
This question addresses the problem of passing a plain-text password through the shell.
...
2
votes
1
answer
277
views
script arguments in bash
I am working on a a script that need to take two script arguments and use them as variables in the script. I couldn't get this working and unable to find out what I am doing wrong. I see the issue is ...
0
votes
2
answers
317
views
Pass multiple arguments from single line from a text file to teminal
I have a python program that requires 2 arguments input-file and output-file.
It reads input-file and creates a copy of that file with some modifications in the output-file.
I created a text file with ...
2
votes
4
answers
3k
views
Stuck at passing JSON as argument in bash
I know many have asked similar questions, but I can't make it work.
I have a file called Dependencies:
Accounts
Aggregates
Blog
Configuration
Contacts
Contents
DataTypes
Forms
Geo
Globalization
Media
...
1
vote
1
answer
167
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/$...
1
vote
1
answer
897
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
880
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
1k
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
104
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
987
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.
...
1
vote
1
answer
555
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 ...
10
votes
1
answer
2k
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
32
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
1k
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
2k
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
1
answer
384
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
156
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
1k
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 ...
3
votes
4
answers
1k
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
237
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 ...
2
votes
2
answers
210
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
479
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 ...
3
votes
1
answer
7k
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
118
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
141
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
1k
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
336
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
526
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
515
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
1
answer
202
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|--...
2
votes
3
answers
391
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
171
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
4k
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
439
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
189
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
333
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
826
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
69
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.
...