Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [arguments]

An argument is usually defined as the actual value passed to a function, procedure, or command line program.

Filter by
Sorted by
Tagged with
0 votes
1 answer
50 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 ...
Vlastimil Burián's user avatar
0 votes
1 answer
41 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 ...
Stewart's user avatar
  • 14.2k
3 votes
1 answer
251 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. ...
Ned64's user avatar
  • 8,934
0 votes
2 answers
84 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 ...
guttermonk's user avatar
2 votes
2 answers
196 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, ...
Convexity's user avatar
  • 121
1 vote
1 answer
87 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 ...
programmer Erfan's user avatar
1 vote
2 answers
124 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. ...
Jesse's user avatar
  • 351
2 votes
1 answer
114 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 ...
MO12's user avatar
  • 391
0 votes
0 answers
42 views

How to start openvpn without any daemonization and log redirection?

I want effectively a debug modus, i.e. I do not want openvpn to fork I want all output in the stdout/stderr and nothing in various logs. How can I do that? I could stop forking with a --daemon=0, ...
peterh's user avatar
  • 9,848
0 votes
2 answers
211 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 ...
Data Engineer's user avatar
2 votes
4 answers
2k 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 ...
Saeed Neamati's user avatar
1 vote
1 answer
58 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/$...
Kes's user avatar
  • 859
0 votes
1 answer
291 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 ...
morpheus's user avatar
  • 115
0 votes
1 answer
530 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 ...
J.Doe's user avatar
  • 103
8 votes
1 answer
893 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 ...
kjo's user avatar
  • 15.7k
0 votes
1 answer
72 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: #...
user avatar
0 votes
3 answers
453 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. ...
user3045272's user avatar
0 votes
1 answer
434 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 ...
BNT's user avatar
  • 3
9 votes
1 answer
1k 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 ...
xtropicalsoothing's user avatar
0 votes
1 answer
29 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 ...
Vera's user avatar
  • 1
0 votes
2 answers
920 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 ...
Pinkurauchin's user avatar
0 votes
3 answers
1k 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 ...
funguy's user avatar
  • 3
0 votes
1 answer
316 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="-...
Matt H.'s user avatar
0 votes
1 answer
79 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 ...
Arno's user avatar
  • 103
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 ...
ChennyStar's user avatar
  • 1,795
3 votes
4 answers
660 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 ...
Brendan's user avatar
  • 29
1 vote
1 answer
149 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 ...
Mike's user avatar
  • 459
2 votes
2 answers
150 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-...
Vera's user avatar
  • 1
0 votes
1 answer
383 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 ...
Vera's user avatar
  • 1
2 votes
1 answer
5k 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 ...
Shriram's user avatar
  • 216
-1 votes
1 answer
86 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 ...
Leland Kilborn's user avatar
0 votes
2 answers
86 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 ...
sudoer's user avatar
  • 55
2 votes
1 answer
965 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 ...
Edgar Magallon's user avatar
2 votes
3 answers
241 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 ...
Steven Lu's user avatar
  • 2,312
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 ...
Yoh's user avatar
  • 1
1 vote
2 answers
436 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 \ --...
nalzok's user avatar
  • 401
1 vote
2 answers
395 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 ...
user3118280's user avatar
1 vote
1 answer
140 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|--...
Amarakon's user avatar
  • 333
2 votes
3 answers
297 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. ...
user2514157's user avatar
0 votes
2 answers
127 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() { ...
Tac Tacelosky's user avatar
1 vote
1 answer
3k 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....
Dirk Horsten's user avatar
0 votes
1 answer
387 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 '...
user598527's user avatar
1 vote
2 answers
144 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 ? ...
Damn Vegetables's user avatar
0 votes
0 answers
230 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 ...
bossu's user avatar
  • 1
0 votes
1 answer
693 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?
Lite Riyusaki's user avatar
0 votes
1 answer
45 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. ...
Gyari's user avatar
  • 15
2 votes
3 answers
222 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 ...
akansha's user avatar
  • 21
0 votes
1 answer
97 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. # ...
markling's user avatar
  • 213
0 votes
1 answer
964 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 ...
Tom L.'s user avatar
  • 3
1 vote
0 answers
384 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://...
Gabriel Hayes's user avatar

1
2 3 4 5
11