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
2answers
31 views

how do you read in the arguments in separate variables

Reading in arguments from the command line is pretty easy, $1 $2 $3 But! if I want to do a loop that assigns $1 to $arg1, $2 to $arg2 I don't want to do it by entering arg1=$1; arg2=$2, I want to ...
3
votes
1answer
54 views

getopts gets no arguments when function is called inside while loop

I am trying to call a function in a while loop passing some arguments. However, getopts can only get the arguments for the first call. Here's a minimal example: function add_all_external_services() { ...
0
votes
0answers
19 views

Passing directory path as arguments and extract columns from files to make a new file with horizontal concatenation

I need a shell script which takes in the path of directories as arguments. The directory contains similar named files for eg. file1.dat, file2.dat etc. I need to take file1.dat from all the ...
0
votes
1answer
31 views

Why does host and nslookup think IP address is a hostname?

Why does this command fail (this is a simplified version of the actual command)? /tmp $ echo 74.6.231.20 | xargs -n1 -I {} echo "$(host -d {})" Trying "74.6.231.20.<REDACTED>.<...
2
votes
1answer
85 views

Can shell arguments be enclosed in characters *other* than single and double-quotes?

I have a script that takes a MySQL SELECT query as its sole argument. Typically I enclose that query in single quotes and use double quotes within the query for enclosing the strings that are ...
0
votes
0answers
32 views

Bash script that accepts options given after arguments in command line

I have a bash script that accepts a number of optional flags and two required arguments. Currently, if the command line call is ~/script.sh -a -b arg1 arg2 it works just fine, but if the call is ~/...
11
votes
1answer
1k views

Why does position of -C matter in git commands?

The following works: git -C ~/dotfiles status But this fails: git status -C ~/dotfiles Why is this?
0
votes
1answer
29 views

How do I ask for user input and pass into a file while debian package installation?

I would like add some parameters into my .service file such hostname, IP, username, password, during debian package installation. I created a debian package installion for my python script but I do ...
2
votes
1answer
67 views

MacOSX: Number of arguments on command line

This: #!/bin/bash # Run command ~100Kbytes long /bin/echo $(perl -e 'print "x"x100000') | wc # Run command ~54Kbytes long # This line fails: line 7: /bin/echo: Argument list too long /bin/...
0
votes
1answer
50 views

How to join bash function arguments into one

I have this situation at hand: simple_git_push(){ export cm_args="${@}" ( set -eo pipefail; commit_msg="$(echo "$cm_args" | tr -d '[:space:]')" # trim ...
0
votes
1answer
26 views

How to pass arguments to a single command from multiple files?

I am using the convert command to annotate images with text: convert -pointsize 20 -fill green -draw 'text 270,460 "[TEXT TO ANNOTATE]" ' [INPUT IMAGE NAME].jpg [OUTPUT IMAGE NAME].jpg I ...
0
votes
2answers
226 views

Programmaticaly open new terminal with Bash and run commands, keeping job-control

In an X session, I can follow these steps: Open a terminal emulator (Xterm). Bash reads .bashrc and becomes interactive. The command prompt is waiting for commands. Enter vim 'my|file*' '!another ...
1
vote
1answer
44 views

Zsh - The Last Argument Passed to a Shell Script?

how to get the last argument passed to a shell script in zsh shell? $ example.zsh arg1 arg2 ... arglast last argument is "arglast"
0
votes
1answer
97 views

Use arguments to pass parameter information to cURL script [duplicate]

I am trying to write a script where the user can pass startDate and endDate via arguments when running the script. Here's my script (saved as test.sh)- VAR="$(curl -f -X POST -H 'X-API-TOKEN: XXXXXX'...
0
votes
1answer
35 views

How to pass argument to file used in nginx command?

I have the following line in my nginx.conf file: proxy_set_header Authorization "Basic dXNlcjpwYXNzd29yZA=="; Currently, the command to start the nginx is: exec nginx -c /etc/nginx/nginx.conf Is ...
0
votes
1answer
28 views

How could I solve the error of psql: Argument list too long?

I have a script that contains the following psql command: psql -h $PHOST -p $PPORT -U $PUSER -d $PDATABASE -c "SELECT COUNT(*) FROM (${SQL%?}) AS query;" when I passed a simple query that query one ...
0
votes
1answer
25 views

dash: echo args exactly with no processing

I want to do sth like zsh's print -r -- ... which just echoes the arguments without changing them at all. printf -- still interprets directives.
0
votes
2answers
29 views

How to execute recursively a program on every files contained in directory with find

I wrote an executable that I want to execute on all the files contained in a directory. This is what the program looks like: #include <stdio.h> #include <stdlib.h> #include <sys/types....
0
votes
2answers
335 views

How to pass empty args to command [duplicate]

So I have this: export ti_arg=''; if [[ -t 1 ]] ; then # allow us to kill container if attached to terminal export ti_arg='-ti' fi ( cd "$(dirname "$BASH_SOURCE")" docker build <...&...
2
votes
3answers
200 views

How can I pass output from command as list of arguments to a script?

I want to add content to a beginning of each file in current directory. I need to learn how to take all file names from current working directory at once and put them as arguments; I don't need to do ...
0
votes
2answers
52 views

bash script passing a command as an argument

The selection should be based on submitting an argument when the script is executed. #!/bin/bash #This script echoes a text and creates a file echo "welcome. Will create a file with content in this ...
3
votes
1answer
193 views

How to check if all arguments are files?

How do you check if all arguments passed to a shell script are files? I tried to use the $@ parameter and -f with an if statement.
0
votes
2answers
39 views

Having trouble allowing only one argument

I am a beginner at Bash scripting and my script is not behavioring properly. I do not know how to fix it or the proper way to code it. The user should only be able to enter one argument. ($ nowOn ...
2
votes
1answer
37 views

How to append arguments in a ZSH loop and then pass them to a command?

Using mkvmerge, I want to add audio tracks to several MKV clips that are arranged like this Clips_folder /spa/clip1.mka /spa/clip2.mka /ger/clip1.mka /ger/clip2.mka /clip1.mkv /clip2.mkv That's the ...
0
votes
1answer
291 views

Pass Bash associative arrays as argument to jq filter

I am working with some location data and am querying an API with U.S. postal codes and returns a result like: { "resultStatus":"SUCCESS", "zip5":"30301", "defaultCity":"ATLANTA", "...
3
votes
2answers
96 views

Pass options to AWK script bypassing AWK

Can I get arguments that happen to be AWK options passed directly to a pure AWK script? Example script: #!/usr/bin/env -S awk -f BEGIN { if (ARGV[1] == "-h") print "whoop" } I want ./myscript -h to ...
-1
votes
2answers
137 views

sudo execute as other user with parameters

I created a (system) user, eg: mysysuser, and some sudo rules so it can do some maintenance in other users folders. This script needs to run as other user but also needs some parameters. Therefore, ...
0
votes
1answer
347 views

Pass regex to command while using zsh

In bash I can do the following: apt install blabla* But in zsh I get zsh: no matches found: blabla* Unless there is a file in the current directory called blablabla. This also causes issues with ...
0
votes
1answer
55 views

bash: syntax error near unexpected token `foo'

I have a command I am trying to alias for simplicity: php artisan route:list | (head -n 3; grep checkout) This command shows me the header of this table and searches for the route. The result looks ...
-1
votes
1answer
23 views

Unable to pass an argument to a function

For my homework, I need to have a function in my code to earn extra credit. I have a script that takes the second argument and makes a folder from what is passed. The code works with the argument ...
-3
votes
1answer
612 views

“Assume that the file name is given as command line argument”, what is meant by that?

I need to write a shell script for displaying the total number of words, characters, and lines in a file, but the filename is "given as command line argument". What is meant by that and how do I use ...
0
votes
2answers
83 views

What’s the difference between providing input to a command via an argument to that command and providing input through a shell redirection operator?

When I use my shell’s redirection operator to provide a (non-existent) filename to the grep command, the error message about that file not existing is displayed by my shell. But when I provide that ...
0
votes
0answers
30 views

How to pass a folder as argument to the executing script? [duplicate]

I would like to execute a script(h.ksh) with the passing argument kim (which is a folder), so when I run the command h.ksh kim the folder "kim" will be used as a variable in the h.ksh Do I need ...
3
votes
3answers
153 views

Find exec sh: Shell variable not getting passed to subshell

Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension. FIND(){ find . -type d -exec sh -c ' for d ...
17
votes
5answers
2k views

How can I conditionally pass an argument from a POSIX shell script?

#!/bin/sh echo "Noise $1" echo "Enhancement $2" for snr in 0 5 10 15 20 25 do python evaluate.py --noise $1 --snr 25 --iterations 1250 --enhancement $2 done If $2 is not specified, I don't want to ...
1
vote
3answers
562 views

Changing argv[0] from the command line

I remember many years (decades) ago using a system where one could say something like: $ realname:newname A B C and the program would be invoked with argv = { "newname", "A", "B", "C" }. I don't ...
0
votes
3answers
33 views

Nested shell script doesn't work with list variable

I have created the following two minimal shell scripts... test1 #!/usr/bin/env bash letterList=$1 for letter in $letterList do echo $letter done and a second test2 #!/usr/bin/env bash ...
1
vote
2answers
491 views

Passing options to cmake in bash script

I am trying to write a script that will build multiple cppUtes lib.a files for different sanitizers with a bash script. When trying to pass the compiler flags as variables to cmake I am unable to ...
1
vote
2answers
1k views

How to xargs multiple string arguments to one command

like this: echo $USER $PASSWORD $RESOURCE_MACHINE $SELECT_SQL $TARGET_MACHINE $INSERT_SQL | xargs -n6 bash -c '/usr/bin/clickhouse-client -u $1 --password $2 -h $3 -q $4 | /usr/bin/clickhouse-client ...
12
votes
3answers
1k views

Is passing a different $0 to a child bash script possible?

I know that this may sound as "not as intended by designer" but I have real life situation where a bash script I am modifying needs to call another bash script that I am not allowed to modify. That "...
0
votes
0answers
43 views

How can I safely pass an argument containing '{{}}' to a bash script? [duplicate]

The following arguments are valid for docker command: docker ps -f"status=exited" --format 'table {{.Names}}' #output: # jovial_hellman # modest_blackwell So I have created this script docker-ps-...
3
votes
1answer
135 views

Get and set the script arguments from within a function in bash

Context: I have an old bash script with a big section parsing its arguments. It happens now that I need to call this section twice, so I plan to move it to a function to avoid code duplication. ...
2
votes
1answer
32 views

Temporary display full name of argument instead of short name/abbrev

After an command, where the user should give an output location with -o, I wondered if there is an (standard) command that temporary displays the full name of the given argument, like the -o, that ...
1
vote
1answer
89 views

problem escaping quotes in script

I'm constructing a command line for use with the 'mogrify' tool [part of imagemagick]. the finalised command line looks something like this : mogrify -stroke yellow -draw 'line 0,0 0,319' -draw 'line ...
25
votes
2answers
5k views

Why does rm manual say that we can run it without any argument, when this is not true?

We can see that the synopsis of rm command is: rm [OPTION]... [FILE]... Doesn't it mean that we can use only rm command without any option or argument? When I run the command rm on its own, the ...
0
votes
1answer
364 views

curl: Argument list too long

I got an error for this line: curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE" curl: Argument list too long How I could fix it?
2
votes
2answers
140 views

“--numeric-suffixes” does not allow an argument with “split”

I'm trying to use the split command for a shell script I'm writing and I want to use the --numeric-suffixes flag in order to start my file count from 1. I try: split -a 1 -l 2 --numeric-suffixes=1 ...
-1
votes
2answers
39 views

Stop executables and built-ins from interpreting a string argument starting with - as a switch? [duplicate]

Let's say I want to search a file for a string that begins with a dash, say "-something": grep "-something" filename.txt This throws an error, however, because grep and other executables, as well as ...
0
votes
1answer
88 views

Why do these rsync filter args fail in bash when passed in array?

Why does this rsync command work when I give it literally but not when I create it from variables? Here are the variables - first the options I'm passing to rysnc, as an array: $ echo "${options[@]}"...
0
votes
1answer
96 views

Using loop in script for command line arguments

So I am trying to sort files with specific extensions into specific folder (ones that have been chosen by user by command line arguments) Lets say $1 (.jpg) $2 (.docx) etc The script is all working ...

1
2 3 4 5
9