Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [arguments]

An argument is usually defined as the actual value passed to a function, procedure, or command line program.

6
votes
2answers
351 views

How to have a script work with “$@” or a default list of parameters while not breaking paths with whitespace?

I want a script that will run another utility over some default paths if no parameters are passed to it; ideally I want this safe for paths that contain spaces. So far I have script.sh: #!/bin/sh ...
0
votes
1answer
110 views

Understanding the combination of ufw --force enable

I rent a remote machine with Debian/Ubuntu and desire to filter all ports I don't use through iptables via ufw. The only ports I allow (both with TCP and UPD) are 22,25,80,443. If I understand man ...
0
votes
1answer
20 views

Require command line argument for script to run [closed]

I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty. ...
2
votes
3answers
155 views

'rename' with expression|replacement with a leading '-' (hyphen|minus)

I have many files like xyz_123_foo.ext for which I would like to add -bar to the filenames at the end to result in xyz_123_foo-bar.ext. I tried: rename . -bar. xyz_* which resulted in: rename: ...
5
votes
1answer
524 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 both written directly after a command, so what is the definition or phrasing to explain how to distinct them? In ...
0
votes
1answer
23 views

Does Konsole permit launching a terminal with a custom font-size on the command-line?

If I want to launch a Konsole can I do so with a font-size of 30px rather than the default?
0
votes
1answer
30 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 ...
0
votes
3answers
87 views

Read arguments separated by newline

I have a script and I receive data from stdin as an argument separated by newlines say I have string1,string2 string3,string4 And I want to take sperately string1,string2 and string3,string4. But I ...
1
vote
1answer
51 views

How to make my bash function known to external program

I have bash functions foo and bar in my ~/.bashrc. Function foo calls an external command ext_command that itself takes as one of its arguments another command. I want to pass bar as that command, i....
-3
votes
2answers
164 views

Calling sh with script on stdin and passing command line arguments

This works of course. I can run ./test1.sh cats and the argument cats is passed correctly to ls. $ cat test1.sh #!/bin/sh ls -l $1 Can you tell me how do I make this second example — the same ...
0
votes
2answers
38 views

Are `-name` and `-exec` options or non-option arguments of `find`?

Are -name and -exec options or non-option arguments of find? They look like short options, and they are called find expressions, if I am not mistaken. For example, find . -name "*.txt" -exec echo {} ...
4
votes
2answers
336 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
159 views

Does the system-wide limit on argument count apply in shell functions?

The other question asks about the limit on building up commands by find's -exec ... {} +. Here I'd like to know how those limits compare to shells' inner limits. Do they mimic system limits or are ...
1
vote
2answers
109 views

How does the find command know how many arguments to feed with “-exec … {} +”?

In a command like this: find /data ! -type d -exec rm -f {} + the + is for batch execution of rm -f. find should batch as many arguments as possible. But how does it know the limit?
1
vote
4answers
223 views

Argument list too long error with makefile

In a makefile, I have @echo "$(IGNORE_DIRS) $(CLEAN_FILES) $(CLEAN_DIRS) $(REALCLEAN_FILES)" | tr ' ' '\n' >> $@ The problem is that $(CLEAN_FILES) is quite large, so when I run make, I get ...
1
vote
1answer
40 views

Partially use the -y argument when installing things in Debian in one line

I have a long apt-get install sequence and for most software packages I need the -y argument. I could do the following in two lines: apt-get upgrade unattended-upgrades sshguard curl wget git ...
1
vote
2answers
56 views

How can I provide an array as a file argument to a script, so that each element is like a line in a file?

Suppose a bash script expects an argument to be a file. But we have a bash array, and would like to provide the array in some way as an argument to the script, as if there were a file whose lines are ...
4
votes
1answer
143 views

First argument passed to wrapper script is ignored

So I've got the following script: #!/bin/bash echo '-------------------------' echo $0 echo $1 echo $@ echo '-------------------------' exec su -- someuser -c "/tmp/elasticsearch-6.4.2/bin/...
3
votes
1answer
155 views

does bash `shift` command change argument count `$#`

When I use the bash shift command, does that change the argument count in $#? Note from author: When I had this question I did not find it (yet) on this community. Therefore I simply tried it and ...
0
votes
2answers
141 views

How to pass multiple parameters to su <USER> -c “command”

I want to execute composer as non root user. So I renamed main composer executable file to composer-call and then create another executable file called composer. #composer.sh su nginx -c "composer-...
0
votes
0answers
72 views

xargs argument in the middle of command [duplicate]

Why is this command not working? echo 'foo bar' | xargs -I % -L 1 echo yeah % yeah It produces the following output: yeah % yeah foo yeah % yeah bar While I expected the following output: yeah ...
0
votes
1answer
146 views

How to pass argv arguments to a C program using a file or python script in linux?

I used to be able to pass input to C program by first writing a python script and using pipe to send it to the C program as an input or write the output of python script to a file and just doing r &...
0
votes
1answer
43 views

How to detach-sign a file with a specific private key? || Why this fails?

I have a .tar.xz file which I would like to detach-sign using my gpg private key. The problem is, I have multiple of private keys imported to my keyring and need to choose, which one to use. ...
0
votes
3answers
46 views

How to parse arguments with space inside bash function

In bash I am calling function: myFunction "1 2" myFunction() { echo "$1" echo "$2" } this prints me "1 2" and empty row. How I can parse arguments so it will print on one row 1 and ...
2
votes
1answer
47 views

Optional commands for bash script

I have a Bash script that sets various environment variables and runs a program. I want one of those variables to change if I run the command with an argument debug. I know 100% how to do this in Lua ...
2
votes
1answer
57 views

Escape keywords with tmux send

Using tmux to send commands along from one terminal to another, I realize that $ tmux send -t mySession "text" ENTER correctly sends text, but $ tmux send -t mySession "up" ENTER sends text again, ...
1
vote
1answer
63 views

Using the 'a' and 'c' options with the 'dash' command in Unix [closed]

What do the options 'a' and 'c' do when there are used with the command 'dash'? I was unable to understand what that command actually does! I have tried reading the man page but didn't exactly ...
1
vote
4answers
66 views

Pass function argument to defined variable

How can I "inject" a function argument to a defined variable like in this example? mood="i am $1 happy" happy () { echo "$mood" } happy "very" Current output: i am happy Desired output: i ...
1
vote
1answer
47 views

Why does my script not take command arguments?

I have a script: #!/bin/sh function usage() { cat << EOF >&2 Usage: $0 [-h] [-rs <start_num>] [-re <end_num>] -h: help: displays list of options for command $0 -rs<...
2
votes
1answer
115 views

Moving random files using shuf and mv - Argument list too long

I have a directory containing nearly 250K files, which are lots of files, and I want to move x random files to another directory. I searched and I got the solution of using the shuf and mv commands ...
0
votes
1answer
30 views

How to handle options when opening a file passed as argument? [closed]

I am trying to open a file through a script; as long as I pass the file as the first argument there are no problems; for instance: $ cat textExample.txt Much I marvelled this ungainly fowl to hear ...
2
votes
1answer
35 views

Generating quoted command arguments

I'm working with a HTTP API that demands a very particular set of signed headers + JSON body. And I really want to cURL it for debugging and sanity in general. So, I've written a small script that, ...
0
votes
4answers
83 views

Creating n variables in Bash without assigning them one by one?

How do I create n variables in shell scripts without explicitly assigning them? What I mean is something like a loop that creates var1, var2, var3,...,varx, where x is a variable I set earlier, ...
0
votes
1answer
151 views

capture output from java

I am trying to do that : #!/bin/bash set out=$(java -jar -Xmx1024m myJava.jar '$1' '$2' '$3' '$4') echo "$out" python myPython.py $out but with no success... I tried with and without quote (because ...
0
votes
2answers
59 views

Keeping quotes passed to a perl wrapper script

I'm writing a small perl wrapper to setup environment variables, etc., then invoke a command by the same name. ./foo.pl -a one -b two -c "1 2 3" -d done When I output @ARGV, the "" around 1 2 3 have ...
0
votes
2answers
32 views

Bash : Give builded array to function as a list of argument?

I have this issue with borgbackup, but because the reaction is the same, I will use rsync in my example. I want to build an array of arguments by adding a prefix to each, and then give that array to ...
-5
votes
2answers
101 views

Signal the end of option arguments: double dashes `--` vs single dash `-`? [duplicate]

I notice in https://unix.stackexchange.com/a/459007/674, that single dash - is used to signal the end of option arguments. Is it correct that double dashes -- can also signal the end of option ...
1
vote
1answer
35 views

ffmpeg truncates paths on output when there are dots involved when run on bash

If I have a path with dots in the path, for instance: /home/user/Documents/hello/test.testing_23-24.123/test.testing_23-24.124 ffmpeg can locate the file if you pass the file's path as an argument ...
28
votes
2answers
2k views

Why is `sort < “$f1” ` preferred over `sort — “$f1”`, and why is this preferred over `sort “$f1”`?

From https://unix.stackexchange.com/a/458074/674 Remember to use -- when passing arbitrary arguments to commands (or use redirections where possible). So sort -- "$f1" or better sort < "$f1" ...
5
votes
3answers
956 views

unshift args after calling shift 1

I have this scenario first_arg="$1"; if foo; then shift 1; node foo.js "$@" elif bar; then shift 1; node bar.js "$@" elif baz; then shift 1; node baz.js "$@" else node ...
8
votes
3answers
718 views

Shell: Using function with parameters in if

I'm trying to execute the code below but when I try to use my function in the if statement I get the -bash: [: too many arguments error. Why is it happening? Thank you in advance! notContainsElement ...
2
votes
1answer
69 views

Detect optional function argument (array)

Consider this function: function add_one(in_ar, each) { for (each in in_ar) { in_ar[each]++ } } I would like to modify it such that if a second array is provided, it would be used instead ...
1
vote
2answers
116 views

find inside shell function

I try to put find inside function and catch an argument passed to this function with the following minimal work example: function DO { ls $(find . -type f -name "$@" -exec grep -IHl "TODO" {} \;) ...
0
votes
2answers
800 views

map array of arguments and then convert to string

Say I have these bash functions in a script: foo(){ my_args_array=("$@") export my_args="${my_args_array[@]}" bar $my_args } bar(){ echo "number of args: $#"; } foo a b 'c d e' if I run ...
5
votes
4answers
576 views

Pass arguments for use in a grandchild process

I have a list of arguments and three processes: bash_script -> child -> grandchild The list of arguments is aimed at the grandchild. I can modify all three processes. The grandfather script ...
3
votes
1answer
70 views

Executing `sh -c` script through SSH (passing arguments safely and sanely)

I suddenly realized I don't know how to execute things over SSH. I tried to do $ ssh user@server sh -c 'echo "hello"' but it outputs nothing, or rather, it outputs an empty line. If the command ...
1
vote
4answers
136 views

How I can use 'grep' command to grab some value from the arguments?

Actually, I am doing some assignment by follow: 1: Write a program called valid that prints "yes" if its argument is a valid shell variable name and "no" otherwise: What I am doing is I want to ...
0
votes
2answers
47 views

Correct way of building variable length argument line to external command in bash

I need to use "find" command to find several different sets of files in my Bash function, depending on my script input. So, I have thing like: DAYS=30 case $1 in A1) ARGLINE="-name 'FOO*.xml' -or -...
0
votes
1answer
44 views

Turn lines in file into list of input [duplicate]

The command i want to execute: tool <input> [<input> ...] <output> I have the input list in a file, separated by newline. I want to put that file's content into the input field. ...
0
votes
1answer
38 views

the position of parameter of command

I think the position of parameter of any command is not fixed. For example, cp -r ./abc ./def and cp ./abc ./def -r are the same, grep -rnH hello . and grep hello . -rnH are the same... However, ...