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
0answers
46 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
77 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
58 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
23 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
97 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
1k 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
84 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
25 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
64 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 ...
0
votes
1answer
99 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
28 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
126 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
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
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 ...
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 ...
0
votes
1answer
109 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
60 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
52 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
56 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 ...
0
votes
1answer
29 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
0answers
17 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 --...
1
vote
2answers
83 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
1answer
82 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
48 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
258 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 ...
0
votes
1answer
102 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
vote
5answers
104 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
47 views

Confusing with passing multi-word arguments [closed]

I'm missing some basic idea about bash, and I don't know what to google! I'm trying to do the following: File future.sh: START_DATE="$1" NEXT=`date "$START_DATE +3 days"` echo $NEXT Then > ./...
0
votes
2answers
59 views

How to add 1st / 2nd argument to bash script being sourced from stdin

I have this: bash <( curl_url='https://raw.githubusercontent.com/oresoftware/run-tsc-if/master/run.sh' curl -H 'Cache-Control: no-cache' --silent "$curl_url" ) the bash script at that url, ...
1
vote
1answer
29 views

Loop function with arguments in another loop function with arguments

# Print $1 $2 times function foo() { for (( i=0; i<$2; i++ )); do echo -n $1 done echo } # Print $1 $2x$3 times function bar() { for (( i=0; i<$3; i++ )); do foo ...
0
votes
1answer
90 views

Bash: pass batches of files to python script

I have a python script that takes a path where a bunch of text files are located to process them somehow. Since there are too many files I want to use batches using a bash script to pass just some of ...
0
votes
1answer
35 views

Script Integer getting prefixed with "

I am running a jar file using a very basic shell script (I literally just need this to run on startup of a NAS). However, I am getting some rather unexpected behavior: Script looks like this: java -...
2
votes
1answer
116 views

zsh: reuse all arguments from previous command

In zsh, the key combination Alt+. is bound to insert-last-word, and it will insert the last argument from previous command on the current command line. I am looking for a keybinding / shortcut that ...
2
votes
2answers
187 views

/usr/bin/truncate: Argument list too long

I want to use the truncate command to create a huge number of small files for testing. I tried the command with a small number of files (100) and it worked. When I changed the number to 1000000, it ...
0
votes
0answers
32 views

Can program arguments on unix contain null bytes?

I'm pretty sure as the array elements are null-ended I can optimize the check away, but is that always the case?
-1
votes
2answers
49 views

Passing txt file as an argument to a script while running

I have a script as below for File in $(cat $IMPORT_PATH/*.txt); do echo `date +'%m-%d-%Y %H:%M:%S'` "starting $File execute" > $Import_Success_Log ./cli.sh -a execute -i ...
2
votes
2answers
65 views

How to correctly identify the order of parameters?

This is my assignment. The task is to output n longest lines from the input file(s). If there is no argument for n, the the default of value n is 5. If there is no files in the parameter, the standard ...
0
votes
2answers
326 views

Check mandatory argument of parameters

I have script with several parameters that have required argument: while [ "$1" != "" ]; do case $1 in -f | --first ) shift first=$1 ...
3
votes
0answers
58 views

Positional arguments when sourcing (.) a file in sh/bash [duplicate]

In bash, when you source a file with dot: . /some/script you can pass positional arguments to that script: . /some/script hello world and then access them in the script with $1, $2, ... etc as ...
1
vote
1answer
880 views

if condition in bash getting too many arguments

I am almost new with bash. I am sorry if this question has been answered somewhere else but I didn't find anything which I could understand. I am making an if condition: if [ $inputstring = $INPUT ] ...
5
votes
2answers
92 views

How do I add an arg to $@?

I like to be able to ... && add-arg 'something', and have 'something' be added to the positional arguments, kind of like an inverse shift. I tried ... && set "$@ something", but this ...
0
votes
2answers
124 views

Can I pipe stdout to the middle of a command with emacs?

The command emacs -nw foo -f org-mode opens the file foo in emacs in org-mode. Now, suppose that the filename foo is the output of a script. How could I pipe to my command? So, I'm trying to get ...
0
votes
1answer
49 views

Start new shell with positional parameters

With Python, I can start a session with positional parameters: $ python3 - aa >>> import sys >>> sys.argv[1] 'aa' However it does not seem to be possible with shell: $ sh - aa sh: ...
2
votes
2answers
153 views

Print out argument value in for loop

This is the script user@linux:~$ cat script.sh #!/bin/bash for i in `seq $#` do echo $i done user@linux:~$ Output user@linux:~$ ./script.sh a b c 1 2 3 user@linux:~$ Desired Output I would ...
0
votes
1answer
903 views

How to print out each command argument with echo? [duplicate]

According to this answer ... A command is split into an array of strings named arguments. Argument 0 is (normally) the command name, argument 1, the first element following the command, and so ...
1
vote
0answers
81 views

LFTP script file arguments

I've got an issue while using LFTP with some script files. lftp -f download.lftp the script looks something like that for now: open -u someurl mirror -i "somefile*.zip" --only-missing ... somehow ...
5
votes
1answer
1k views

Bash echo $-1 prints hb1. Why? [duplicate]

If I ask bash to echo the -1th argument it prints hb1: echo $-1 hb1 Why? What is it accessing?
2
votes
2answers
176 views

Regex to check arguments of command

I want to use grep to check if a command called cmd that was ran, contains the word name as an argument. (I know about about !* in Bash, I don't want to use it). Let's say I have the command in a ...

1 2 3 4 5 8