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
2 answers
14 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 ? ...
user avatar
0 votes
0 answers
24 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 ...
user avatar
  • 1
0 votes
1 answer
32 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?
user avatar
0 votes
1 answer
41 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. ...
user avatar
  • 13
2 votes
3 answers
44 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 ...
user avatar
  • 21
0 votes
1 answer
26 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. # ...
user avatar
  • 147
0 votes
1 answer
26 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 ...
user avatar
  • 3
1 vote
0 answers
61 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://...
user avatar
0 votes
0 answers
35 views

How to pass an array whose elements contain spaces from a script to a function in bash/zsh?

I'm using the zsh shell but would like solution that would also work in bash. I have a script and a function I want to use together. The script myfilter: #!/bin/bash result=() for arg in "$@&...
user avatar
0 votes
0 answers
49 views

Secure transfer of arguments to a program (dash/bash)

Transfer via stdin #!/bin/dash echo 'password' | program - Transfer via stdin using an intermediate variable var_pass=$(echo 'password') echo $var_pass | program - unset var_pass Transfer via ...
user avatar
  • 127
0 votes
1 answer
47 views

Help understanding Bash command-line argument parsing code

I want to take two arguments and a third optional one for a script I am developing. I am new working with bash so I have been copying and trying to understand the following code that does what I want (...
user avatar
-1 votes
3 answers
163 views

Parse comma- and colon-separated numbers into to array values in Bash script

I have a Bash script for deploying a service. It needs an update in the form of an additional command line argument for specifying ports for launching multiple instances of the service. The argument ...
user avatar
0 votes
3 answers
185 views

How to run all command line arguments via another shell?

I have a script tempenv which I'd like to use as follows: $ tempenv ls -l tempenv looks like this: #!/bin/bash setarch ... /bin/bash -c $@ However, it doesn't work as I intend. Instead, it only ...
user avatar
2 votes
1 answer
395 views

What does crontab do when I give no argument?

I accidentally typed this command without any arguments and hit enter, and it seems the terminal is running something, so my question is what crontab do when I give no arguments? [root@localhost ~]# ...
user avatar
  • 23
-2 votes
1 answer
38 views

Checking for numeric arguments

I want to check function arguments, and check whether $2 and $3 are numeric Is the following line the way to use the AND statement? Am I using = the correct way to check for numeric digits? if [[ &...
user avatar
0 votes
2 answers
866 views

How to check arguments given to a bash script efficiently?

I wrote a bash script but since I'm a self-learner bash rookie, I wanted to ask if I can check the given arguments more efficiently. I also googled about this and checked topics here but the examples ...
user avatar
-1 votes
2 answers
100 views

How to properly parse a quoted arg-list string in a shell script?

Summary How to convert a single string a "b" 'c d' $'e\nf' into separate arguments, respecting quotes and preserving whitespaces and newlines? Question I'm trying to read and process the ...
user avatar
  • 99
0 votes
0 answers
87 views

Alternatives to getopts for referencing flag next to argument

So I'm currently writing a script that takes arguments next to options to assigns them to variables. From the command line it'd look something like this >> ./myscript.sh --gpu 2 --cpu 12 --mem ...
user avatar
  • 187
0 votes
0 answers
419 views

Why does using subprocess not give complete output for grep?

I am trying to use subprocess.check_output() to grep my a Git repo, but the output differs from when I run grep in my terminal. When I grep in my terminal it gives around 100 lines of output, but when ...
user avatar
2 votes
2 answers
142 views

AWK Command Argument Error

I have a dataset which contains contact information of students, the sample data set is as follows First Name, Last Name, Address, Phone Number John, Doe, "House # 11, Street xyz, Road, Area"...
user avatar
0 votes
1 answer
48 views

passing arguments inside quote, e.g. screen -dm ' ls /home/$dir1 '

I use the following script #!/bin/bash echo 'Please enter the password of your XXXX:' read -sp 'Password:' password screen -dm bash -c ' BLABLA ' Problem is that my commands in BLABLA include the ...
user avatar
  • 1
1 vote
0 answers
81 views

Argument list too long while generating txt file which includes file names in a directory [closed]

I am trying to write all of the file names in the directory into txt file. I used the command, ls /path/of/directory/ > file_name_list.txt But it gives error ls: cannot open directory /path/of/...
user avatar
-2 votes
1 answer
83 views

In the synopsis of a man page, what do ellipses following brackets mean? [duplicate]

The following image is from the POSIX documentation's section on Utility Argument Syntax. My question is this: Are the two argument forms in the image more or less identical, besides one using the ...
user avatar
0 votes
3 answers
1k views

Detecting getopts `--` (double dash) to issue a message

I am using the customary way of using getopts through a variable named arg. I can capture the option names as follows. Is it possible to detect the moment getopts reaches "--" so that I ...
user avatar
  • 21
0 votes
1 answer
85 views

Using a script that opens vim in terminal instead of gvim (is ita bad idea?)

On my system i only have vim installed, not gvim. I am also using qutebrowser. In qutebrowser you can set a command to open your editor to edit some text. Due to how it quotes commands, it seems not ...
user avatar
0 votes
1 answer
48 views

bash - Script to output domains MX-es using arguments

I am trying to make a bash script that shows me the domains MX-es of one or more domains given as arguments when running it. Example script call: ./domains.sh domain1.com domain-no-mx.com domain2.net ...
user avatar
  • 1
3 votes
1 answer
79 views

Does ${@:-1} really return last argument?

I am running the following code when I have two arguments if (( $# == 2 )); then : ${fdir:="${@:-1}"} pfm -w2 "" "unspecified -d option" echo "use last ...
user avatar
  • 317
1 vote
2 answers
76 views

How to introduce support for command line options in a script that is written to use positional arguments?

I have a script that is currently used with positional arguments, like this: ./script.sh fname lname address I want to also support ordinary command line options when I call this script, so that I ...
user avatar
  • 113
0 votes
1 answer
48 views

Passing file types to bash function and calling find

I have the following bash function to print between two line numbers, for files watching file types .texi and .org recursively in a particular directory. I would like to be able to supply the file ...
user avatar
  • 317
0 votes
1 answer
68 views

Checking bash function arguments

I would like to check if two arguments to a bash function are numeric, and the last argument is a directory that exists. Have done like this, but the implementation is quite insufficient. if [[ $1 =~...
user avatar
  • 317
1 vote
1 answer
39 views

Adding help option for function

I have the following function that print NUM lines from the beginning of a set of files. The command (function, script, whatever) accepts a variable number of arguments, and I would like to reserve ...
user avatar
  • 317
3 votes
8 answers
885 views

Extract multiple files at once in the terminal

I have a directory containing hundreds of zip files. I want to be able to select about fifty files and extract them all at once using unzip (or 7z) in the terminal. The files have completely different ...
user avatar
  • 3,311
0 votes
0 answers
119 views

how to pass python arguments to a bsub file

I am working with the bsub job submission system from Platform LSF. I need to submit job scripts, but I am running into a problem with passing arguments to the python file that im using in the job ...
user avatar
  • 101
-4 votes
2 answers
51 views

split argument and create a new variables

My argument look like: My_Submit.sh May5_2014 and I want to create a new variable inspired from the argument, this variable should look like May14_5.
user avatar
0 votes
1 answer
102 views

process input arguments to a bash script

I'm processing files with a bash script $ processh.sh file. The input file contains information about the files to process # id path type id1 filename1 csv id2 filename2 id3 filename3 json ... ...
user avatar
  • 2,624
0 votes
1 answer
62 views

Shift: Is there a global version?

in order to parse the arguments list I tried to implement a common top-down parsing scheme. I wondered why my eat() function wouldn't work. Because the positional arguments $1, $2, $3, ... are in the ...
user avatar
  • 303
0 votes
1 answer
105 views

How to preserve spaces in args when running $@ with eval

I'm writing a bash script that runs everything passed to it. I want it to work like so: $ ./myscript.sh echo hello world # should run 'echo hello world' This is my script thus far: #!/bin/bash eval &...
user avatar
  • 1,041
0 votes
0 answers
77 views

.desktop file KDE Service menu - how to copy many files

I have a servicemenuitem for KDE which copies the selected file to the desktop. It works when one file is selected on the desktop, but when multiple files are selected, they are not copied. The -exec ...
user avatar
  • 1
0 votes
1 answer
49 views

Using the "$@" special args in a new bash command (bash -c)

I am trying to run a bash -c command relying on the parent bash scripts arguments via "$@" When running a normal command, I use "$@" and bash does the expand magic for each arg. ...
user avatar
  • 8,260
0 votes
1 answer
500 views

Run executable on background detached from terminal but with arguments

I can run an executable in the background and detach it from the terminal with these commands: $ nohup ./executable & or $ ./executable & $ disown But none work if I send arguments to the ...
user avatar
  • 1
1 vote
1 answer
93 views

Passing arguments to a command safely

It is well known that it's a bad idea to do something of the kind <command> $FILENAME, since you can have a file whose name is for example -<option> and then instead of executing <...
user avatar
0 votes
1 answer
110 views

cd does not take variable as argument in bash script [duplicate]

I'm trying to make a bash script that will give me a command that will take a number n as argument and change the directory to the nth directory listed by running ls in the working directory. Here's ...
user avatar
-2 votes
1 answer
119 views

How to make sftp output a working sftp prompt after the connection from CLI arguments is created?

I get a program that stays in input state, the user can type characters but they are useless. The following are the command and the output. After this, the terminal prints the keys pressed. ~  sftp -...
user avatar
14 votes
1 answer
1k views

What is ${@:$#} exactly?

I tried to to run echo ${@:$#} and it echoes my current shell. I found out that echo ${#} echoes 0. I didn't find any resources about the results. I am trying to understand that part so I can ...
user avatar
0 votes
0 answers
72 views

How to sort command name + arguments output of ps in solaris

Below is my sample output of ps command in solaris myuser 26856 0.0 0.1 1716368 118576 ? S Feb 18 2:17 /web/bea/platform1221/jdk1.8.0_221/bin/java -Djava.security.manager -Djava.security....
user avatar
  • 297
0 votes
2 answers
494 views

How to get the filename from an array of absolute paths of filenames

I have a shell script that needs to delete the file names from the /tmp directory. The file names must be detected from a list of file names passed to my script. ./deletetmpfiles.sh /var/moht/test1....
user avatar
  • 297
1 vote
2 answers
41 views

How can I identify file names and directories from logs of Unix commands?

I have a data-set of Unix commands as input into terminal and I want to use them to compare user behaviours. Different users interact with different directories and files (they are all on separate ...
user avatar
2 votes
3 answers
86 views

Append all files in a directory as cli arguments

I need to run a command that looks like this mycli --file test.zip --file another_test.zip How could I run that dynamically with all zip files in a directory? I'm sure I could pipe the files from a ...
user avatar
  • 375
0 votes
1 answer
89 views

Need cp -ax alternate for Solaris

On my Linux host; this cp command helps copy files and folders both while preserving the timestamp and permissions cp -ax <source file/folder> <destination> Need similar command for SunOS ...
user avatar
  • 297
3 votes
2 answers
1k views

bash script with optional input arguments using getopt

I have copied code from tutorialspoint's getopt article and got the following script to work (sort of): ##argument_script.sh VARS=`getopt -o i::o:: --long input::,output:: -- "$@"` eval set ...
user avatar

1
2 3 4 5
10