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.

2
votes
1answer
83 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
92 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
112 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
37 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 ...
0
votes
1answer
50 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
123 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
122 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
86 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
44 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
56 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
28 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
39 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 ...
0
votes
0answers
19 views

usage of arguments for shortcuts for grep when backslash is used

I would like to make a shortcut for grepping over c++ files and colouring everything nicely. Based on this reply my command would actually look like: grep --color=auto -rn "$(printf %q 'Pipeline \')"...
1
vote
1answer
35 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
27 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
50 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
60 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
46 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
68 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
29 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
31 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
82 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
2answers
60 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
31 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
78 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
29 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" ...
4
votes
3answers
682 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
577 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
53 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 ...
0
votes
2answers
76 views

find inside sh 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" {} \;) ...
-1
votes
2answers
555 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
517 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
60 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
121 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
42 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
38 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, ...
1
vote
1answer
422 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 ...
0
votes
1answer
636 views

how to properly parse shell script flags and arguments using getopts

I'm new to using this : for example ./imgSorter.sh -d directory -f format the scripts' content is : #!/bin/bash while getopts ":d:f:" opt; do case $opt in d) echo "-d was triggered with ...
-1
votes
2answers
138 views

Can you make the `dd` command safe?

We all have (or know someone who has) unintentionally misused the destroy-disk (dd) command. What ways exist (if any) to change the command in the following or a similar way: If /dev/sda is given as ...
1
vote
1answer
43 views

function and pass arguments

So this is my first function: #!/bin/bash lets_print () { echo hello $1 } lets_print Earth lets_print Mars ready to show result user@bash$ ./demo.sh Hello Earth Hello Mars And this is my ...
2
votes
1answer
55 views

bash function arguments strange behaviour

I have the following bash function: lscf() { while getopts f:d: opt ; do case $opt in f) file="$OPTARG" ;; d) days="$OPTARG" ;; esac done echo file is $file echo days is $...
0
votes
1answer
44 views

Empty test handling

Am learning bash and it's confusing how (why) this line of code if [$1 = ]; then works. Can someone please explain. From bash tuturial here under File re-namer (6th block) # a quick check to see if ...
0
votes
1answer
130 views

List of arguments in only one variable in bash

There is an input argument with a list of files (files with wildcards or folders) like this one: list="file1 dir1 **.data **.source" Now each element of this list must be prefixed with --filter=+, ...
0
votes
1answer
245 views

echo huge text giving arument list too long error [duplicate]

Struggling with outputting huge text (around 500 KB) to a file on linux. Text contains spaces, special characters and other.... Getting error /bin/sh : argument list too long #!/bin/bash txt="---huge ...
-1
votes
1answer
472 views

Reading multiple arguments for a shell script from file

I have a shell script that takes three arguments, which need to come from a single line of a text file. Example text file: 1 1 2300000 1 2300001 5300000 1 5300001 7100000 1 7100001 ...
0
votes
1answer
37 views

Make sed work through 2 or more lines (all lines in this case) instead just one [duplicate]

I use Ubuntu 16.04 with Bash and I'm ought to enable http2 for a particular website I have on an Nginx environment. Natively, the utility sed does its text-processing on the first instance in the ...
1
vote
4answers
3k views

How to pass in multiple arguments to execute with .sh script

I have a list.txt file including a list of log file. For example server_log1 server_log2 ........ server_log50 I have another shell script used to download these logs. It worked ...