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
1
vote
1answer
14k views

open eclipse from a terminal and pass a workspace to open

I want to open eclipse through terminal and i am able to do it, but when when eclipse starts it asks for the workspace directory attached the screenshot,and then there i have to specify it, i dont ...
3
votes
5answers
329 views

How to check for “delta” argument like “+10”

I want to pass a numeric value to a bash script, which could be either an absolute integer value (0-100) or a relative "delta" like "+10" or "-50". How would I parse $1 to check for + or - and grab ...
9
votes
3answers
5k views

How to give a comma-separated list as arguments to the next command

I have a script s1 that outputs a list of numbers separated with ',' e.g. 1,2,3,4. Now I want to give these numbers to script s2 as arguments, so that s2 will be run on each of them and output its ...
1
vote
1answer
598 views

How to pass an argument containing double quote to a shell script function?

I have in pull_news.sh (variable declarations omitted): dump_table () { mysqldump --user=${REMOTE_USERNAME} --password=${REMOTE_PASSWORDS} --host=${REMOTE_HOST} --port=${REMOTE_PORT} --single-...
7
votes
1answer
758 views

Word splitting in positional parameters

Consider the following example: IFS=: x="a :b" # three spaces echo ["$x"] # no word splitting # [a :b] # as is echo [$x] # word splitting # [a b] # four spaces Word splitting ...
0
votes
0answers
179 views

HP:the arguments in killall beyond `man killall`

In the tutorial here : /usr/bin/killall -HUP rsyslogd For the command : /usr/bin/killall -HUP rsyslogd In my os,the synopsis info in man killall SYNOPSIS killall [-Z, --context pattern] [-...
0
votes
2answers
49 views

What is the recommending interface to a utility that requires many parameters? [closed]

I'm building a command-line utility that requires six pieces of information to work correctly. It looks like this: fm-git filename repository path comment username password However, on any ...
2
votes
1answer
1k views

Passing options/args/parameters with spaces from the script to a function within

Hello ALL and thanks in advance. I have searched the forum for my situation and have been unable to locate a solution. I've got a script that I am passing arguments/options/parameters to at the ...
0
votes
2answers
547 views

Parsing nested arguments

I am not able to parse the arguments of a script properly. The scenario is explained below. First script (test2.sh): #! /bin/sh arg_part1="./test1.sh '123 789'" arg_part2=456 #Option 1 ${arg_part1} ...
1
vote
1answer
255 views

Provide command line switch after xargs output

Given I use this command: outputStuff.sh | awk -F"-" '{print $5"-"$6}' | xargs someTool (XARGS OUTPUT HERE) --someCommandLineSwitchHere However I need to provide command line switch after the ...
15
votes
5answers
3k views

Hide arguments to program without source code

I need to hide some sensitive arguments to a program I am running, but I don't have access to the source code. I am also running this on a shared server so I can't use something like hidepid because I ...
0
votes
2answers
483 views

How to pass every line of a file as options to a command?

I'd like to write a script that reads a file and passes every line as options (or "option arguments") to a command, like this: command -o "1st line" -o "2nd line" ... -o "last line" args What's the ...
1
vote
2answers
150 views

Combining a parameter argument inside an echo [duplicate]

I use the following script to do the following actions in my environment: Creating an Nginx site conf. Creating a corresponding Let'sEncrypt SSL certificate. Creating a symlink between my sites-...
4
votes
2answers
7k views

Append argument to arguments list

I have the following Bash code: function suman { if test "$#" -eq "0"; then echo " [suman] using suman-shell instead of suman executable."; suman-shell "$@" else echo ...
25
votes
4answers
4k views

Why do I need to use cd “$@” instead of cd “$1” when writing a wrapper for cd?

Elsewhere I have seen a cd function as below: cd() { builtin cd "$@" } why is it recommended to use $@ instead of $1? I created a test directory "r st" and called the script containing this ...
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 /...
0
votes
2answers
2k views

How to get command line flags or options in an executable command program

I made a practice C++ program that generates a new password everytime I execute it, it asks me for the password length and then proceeds to generate a new pseudorandom password. I will add its ...
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 ...
1
vote
2answers
2k views

How to grep command line argument on which RegEx has been applied?

I'm trying to write a script that takes as input a set of integers representing certain /dev/sda's. For example, if the command line arguments are 3 & 5, the output will show the UUID for /dev/...
3
votes
1answer
1k views

Problem with passing path containing spaces and brackets

I use Thunar file explorer and pass pathname and filename to a script audioplay. audioplay runs play command on my android via ssh which plays a song. audioplay script :: cat audioplay if [ $# -eq ...
2
votes
1answer
3k views

Passing arguments with spaces and quotes to a script (without quoting everything)

The following works great on the command-line: $ ffmpeg -i input.m4a -metadata 'title=Spaces and $pecial char'\''s' output.m4a How do I parameterize this command and use it in a script/function? I ...
1
vote
3answers
678 views

check if a shell script takes command line argument before running it

Let see the following code: #!/bin/bash arg=$1 echo $arg If I run it with argument it prints the argument; if not it does nothing. What I want to know, is it possible to find out if it takes a ...
71
votes
3answers
6k views

How does curl protect a password from appearing in ps output?

I noticed some time ago that usernames and passwords given to curl as command line arguments don't appear in ps output (although of course they may appear in your bash history). They likewise don't ...
1
vote
1answer
6k views

bash — parse flags and an expected (non-optional) argument

$ bash file.sh expected_arg -f optional_arg I've seen posts that address using $1 to grab the first argument and posts that address using getopts for parsing flag arguments. I haven't seen a post ...
0
votes
2answers
540 views

Passing in special characters from a perl script to csh

I'm writing a perl script that takes a string and passes it into a .csh script. PerlScript.pl: $CMDLineArgs = "-stuff -more_stuff \'-even_more \"*stuff\" -last_stuff\'"; system(Script.csh $...
1
vote
2answers
251 views

Passing the output of a command to another in one line [duplicate]

I want to take a screenshot with import, and save it into a file whose name is current time. Here is what I've tried: sunqingyao:~$ date '+screenshot-%y%m%d-%H%M%S.png' screenshot-170716-173336.png #...
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 ...
0
votes
1answer
30 views

Does the params and the name affect the command in Linux?

I see the tutorial, when create a user: useradd -g liao1 lamp You see they place the -g liao1 before the lamp, and I tested the: useradd lamp -g liao1 I put the param after the name, I can create ...
1
vote
1answer
2k views

Missing service file for pure-ftpd

Background I want to change some options of Pure-FTPD. Since it has no config file, I need to add command line arguments. My system is Debian Stretch, which uses systemd. What I tried There is no ...
1
vote
1answer
180 views

What are command primaries?

I came across the notion of primaries from running man find: . . . PRIMARIES All primaries which take a numeric argument allow the number to be preceded by a plus sign (``+'') or a minus sign (``...
5
votes
4answers
3k views

grep getting confused by filenames with dashes

I'm having a problem where grep gets confused when the directory contains a file starting with dashes. For example, I have a file named "------.js" . When I do something like grep somestring * I get ...
0
votes
0answers
30 views

Protecting against “-” symbol in filenames [duplicate]

This question is loosely related to this post. The basic idea is that OP had - in filename which broke ls *.vcf. What happened is clearly understood, but the question is then, how could one 'protect' ...
-1
votes
1answer
1k views

Pass argument to function with case statement

I have this code on my inithome.sh: HOMEDIR="/home/$USER/" descomu () { case "$*" in -ut|--user-tar-dir) TARHOMEDIR= "$2" if test "$2" = "" then echo "The direction ...
5
votes
1answer
568 views

How to read from a pipe keeping positional parameters?

I'm writing a small script that I'd like to make it working from a piped input or else from the command-line arguments. my_function() { for i in "$@"; do echo "$i" echo ----- done } if [ ...
3
votes
2answers
3k views

Why am I able to pass arguments to /usr/bin/env in this case?

I read in another answer that I'm not able to pass arguments to the interpreter than I'm giving to /usr/bin/env: Another potential problem is that the #!/usr/bin/env trick doesn't let you pass ...
5
votes
1answer
2k views

Argument list too long

I'm trying to enter a command with VERY big argument (1 MB in size), but it says "Argument list too long." How can I enter that argument? OS: Linux Ubuntu
1
vote
1answer
366 views

How to pipe netcat's output? Problems with xargs and quotes

I'm trying to pipe whatever nc receives with this: nc -l 20000 | xargs /root/test ...and it works fine, except when xargs receives quoted arguments - it splits them as if they were separate... ...
8
votes
2answers
548 views

Detect optional function argument (scalar)

Consider this script: function alfa(bravo, charlie) { if (charlie) return "charlie good" else { return "charlie bad" } } BEGIN { print alfa(1, 1) print alfa(1, 0) print alfa(1, "")...
2
votes
2answers
3k views

Can I introspect the type of a bash variable?

I'm writing a function that outputs dates. I'd like to allow the user to customize the output by supplying arguments to date with an environment variable. To preserve white space in format strings, I'...
1
vote
3answers
2k views

Exclamation marks in bash command arguments [duplicate]

If I type the following command in Bash: echo "dog!!" I don't get the string dog!!. Instead I get something else. I tried to echo the string "dog!!" by echoing "dog\!\!, but it doesn’t work either. ...
5
votes
2answers
574 views

How to re-write this function to avoid argument injection

I have a function in my .bashrc file that allows me to run a script on a remote server with arguments via ssh. Currently, the function contains: function runMyScript { if [ $1 = "s3" ] then ...
1
vote
1answer
685 views

Providing git remote with SSH arguments?

For some reason, my console hangs if I try to run any ssh command. For example: ssh user@server date will hang, ssh -f user@server date works. If I want to include the -f argument in a git remote ...
0
votes
4answers
102 views

Create generic function to ask a question and verify if answer is empty

I am creating an shell application that do a lot of questions and I am using the read -p "<my_question>" <myvar> several times. The problem is that I also want to verify if answers is ...
2
votes
1answer
94 views

Shell function that consumes two arguments per loop iteration

I'm writing some iptables scripts, and I want to write a function that takes an arbitrary number of parameters and consumes them two at a time. Here's an example: #!/bin/sh # Allow inbound sessions ...
1
vote
1answer
88 views

Pass all lines in a file as single space separated argument [duplicate]

I have a txt file: txt1 txt2 txt3 I want to pass all these lines as a single space separated argument: myProgram -a txt1 txt2 txt3 Is there an easy way to do this?
1
vote
1answer
1k views

Pass on arguments with double quotation marks from one bash script to another

A bash scrip is invoked like this: $./script 25 "str1 str2" and it is supposed to launch a terminal, that runs another script that receives both arguments, exactly as they are above (including ...
4
votes
1answer
103 views

Selecting non-existent files with wildcard/regex

I'm trying to convert hundreds of *.jpg files to *.webp files with libwebp on macOS. Particularly, I want to use the command line tool cwebp to perform the conversion. It works like this: cwebp <...
6
votes
2answers
2k views

Command line arguments order

Someone once told me there was a standard when it comes to parsing options on the command line. Something like: ./script.sh [options/flags] [command or file] I understand that when parsing a shell ...
1
vote
1answer
547 views

Using input from two different files in a for loop

I have a list of files that I want to search across a list of database tables: [root@host hs]# head -n 3 tables rec_playinth120116 rec_playinth120216 rec_playinth120316 [root@host hs]# head -n 3 ...
0
votes
1answer
417 views

Using shell script argument?

I have the following script: #!/bin/bash if [ "$1" == "" ] then echo "To start monitor, please provide the server ip:" read STRIP else STRIP=$1 fi ssh 192.168.5.209 ssh root@$...

1 2 3
4
5
9