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
1answer
46 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
81 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
62 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
396 views

How to execute a script on several nodes using Slurm?

I have a R code that I want to execute on several nodes using Slurm, with each iteration of my paramater which goes on a node. This is my Slurm code : #!/bin/bash #SBATCH -o job-%A_task.out #SBATCH -...
-1
votes
1answer
52 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 ...
51
votes
5answers
100k views

Argument list too long for ls

I get the following error when trying to ls *.txt | wc -l a directory that contains many files: -bash: /bin/ls: Argument list too long Does the threshold of this "Argument list" dependent on distro ...
0
votes
1answer
43 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
21 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 ...
6
votes
2answers
1k views

Bash function to wrap program and sometimes append argument

I'm interested in a general solution, but my specific example problem is writing a .bashrc function that wraps grep and appends a file path to the command if missing. Basically, any time grep would ...
0
votes
0answers
50 views

ls --help doesn't work in terminal, why? [duplicate]

Whenever I type a command to get information on, for example: ls --help I get an error: "ls: illegal option -- -" "usage: ls [-ABCDEF...]" Can anyone help me on why my --help isn't working?
-3
votes
1answer
163 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 ...
1
vote
1answer
2k views

How to use ClamAV to scan the memory

How can I only scan the computer RAM for viruses using the ClamAV command clamscan? I already tried, because I found it on ClamWin forum: clamscan --memory But it seems, that the Linux version does ...
0
votes
1answer
310 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 ...
0
votes
2answers
64 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 ...
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 ...
0
votes
3answers
27 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 ...
3
votes
3answers
103 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 ...
68
votes
8answers
116k views

Solving “mv: Argument list too long”?

I have a folder with more than a million files that needs sorting, but I can't really do anything because mv outputs this message all the time -bash: /bin/mv: Argument list too long I'm using this ...
0
votes
0answers
25 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 ...
1
vote
3answers
162 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 ...
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 "...
1
vote
2answers
102 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 ...
60
votes
9answers
144k views

How do I echo just 1 column of output from ls command?

Lets say when I do ls command the output is: file1 file2 file3 file4 Is it possible to display only a certain column of output, in this case file2? I have tried the following with no success: echo ...
3
votes
1answer
127 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. ...
0
votes
0answers
30 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-...
4
votes
1answer
1k views

How to distinguish between a positional parameter and an option?

Both a positional parameter ($1, $2, and so forth) and an option (and/or argument) are written directly after a command, so what is the definition or phrasing to explain how to distinct them? In ...
4
votes
2answers
784 views

find -exec {} + argument list limit

I know that when the maximum argument list size is reached, xargs keeps creating new lists until all of the files are included; but does find -exec <command> {} + do the same thing or will it ...
2
votes
1answer
31 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
2k views

Specify command with quoted arguments in sudoers?

The General Case I'm trying to enable a user to run a sudo command (with arguments) without a password. I can get the NOPASSWD directive to work, but only when the arguments don't contain quotation ...
1
vote
1answer
75 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 ...
-1
votes
3answers
165 views

Why is it uncommon for stdin inputs to have option-like inputs, while common for command line arguments?

POSIX and GNU have their syntax styles for options. For all the commands that I have seen, they accept option-like inputs as command line arguments. Is it uncommon for a program to accept option-...
1
vote
1answer
1k views

Where can I configure Chromium's default command line arguments?

I've seen lots of places people have suggested to store command line arguments, ~/.config/google-chrome-flags.conf ~/.config/chromium-flags.conf /etc/default, My version of chromium doesn't seem to ...
41
votes
7answers
12k views

Multiple arguments in shebang

I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!). I use NixOS, and the first part of the shebang in any script I write is usually /...
24
votes
2answers
4k 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 ...
2
votes
2answers
72 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 ...
0
votes
1answer
167 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?
0
votes
1answer
57 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[@]}"...
-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
61 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
vote
1answer
2k views

handling $1 in shell script directory path

I have this part of the script(bash) that worked absolutely fine until recently but it throws me an error with file not found when using $1 to give directory path. Only difference I know is it stopped ...
1
vote
2answers
104 views

Parsing script arguments after getopts

I have a script where I've implemented switches using getopts. However, I'm having trouble referencing the next argument. My script is for backporting a backup of our website on a local development ...
0
votes
0answers
19 views

How is it possible to call CwRsync.exe via a Bash Script with variables and arguments?

This is the commandline currently used to call Rsync that's part of Cygwin 64 install. rsync -aqHPR $CygSrcRoot/./$FolA1 $CygSrcRoot/./iMazing.Versions/Versions/$FolA1 $CygDstRoot/$DstCountFol --...
0
votes
1answer
32 views

Shell can't resolve argument [duplicate]

I am passing arguments to the shell script below ./script.sh pan.tgz 192.168.3.1 ABCXYZ #!/bin/sh echo $1 $2 $3 file=$1 host=$2 key=$3 curl -kv -o ${file} 'https://${host}/api/?type=export&...
0
votes
1answer
121 views

Why arguments which passed to .sh file are missing after sudo su?

I need to run .sh file on my server from my local machine. I could do it using below command. ssh -p my_port_no -i path_to_key user@ip_address "bash -s" < testOnServer.sh Now I need to pass some ...
3
votes
1answer
3k views

Print only timestamp and message in journalctl

I'm trying to get the last few lines from journalctl so I can feed them into my conky. However journalctl by default provides too much crap that wastes space: With journalctl -u PROCESS -n 5 --no-...
3
votes
1answer
50 views

Is it possible to pass commands as variables to a --dialog script?

Currently I have the below dialog function that I am trying to make into a reusable yes/no prompt where I will be able to call it using YesNoPrompt followed by variables it will be needing. The ...
1
vote
1answer
320 views

awk argument $1,$2 conflict with bash input arguments

I would like to add some awk commands to a bash script. The bash script takes a few inputs, and inputs are passed by $1, $2 and etc. When I call awk, I also want to use $1 to define a position in ...
138
votes
7answers
383k views

Pass the output of previous command to next as an argument

I've a command that outputs data to stdout (command1 -p=aaa -v=bbb -i=4). The output line can have the following value: rate (10%) - name: value - 10Kbps I want to grep that output in order to store ...
1
vote
5answers
113 views

Applying commands to lists

Very often I need to apply a certain simple function to a list (or more precisely to a string where substrings that I want to treat as separate items are delimited by a new line). Say I need to ...
0
votes
1answer
107 views

How many arguments are in `ls -isw 40 /usr`?

How many arguments are in this command line? [me@localhost]$ ls -isw 40 /usr Some say just one, the /usr because 40 is the argument to the w switch not the command and some say two, because ...

1
2 3 4 5
9