Stack Exchange Network

Stack Exchange network consists of 175 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 [parameter]

The tag has no usage guidance.

0
votes
1answer
22 views

How does zsh expand variables before passing to programs?

A basic rule of zsh is that you don't need to quote your variables, for example: % data="single argument" % print -l $data single argument One exception I know of is that if an argument must not be ...
0
votes
1answer
35 views

Translate a single line into a file with one shell command

I'm looking for a convenient command to run from my terminal. At now I'm using $> FILE=./file_for_translate.md && ROW=84 && \ DATA=$(sed -n ''"$ROW"'p' $FILE | trans -no-init -no-...
0
votes
1answer
20 views

How to execute a script on several nodes using Slurm?

I have a R code that I want to execute on several nodes using Slurm, with each iteration of my paramater which goes on a node. This is my Slurm code : #!/bin/bash #SBATCH -o job-%A_task.out #SBATCH -...
2
votes
2answers
90 views

How do I delete files except some specific files passed as parameters?

The task is to write a shell script with n+1 arguments where the first one is the directory and the rest is the specified files and will delete all but specified files. E.g. calling rmexcept . '*....
0
votes
1answer
71 views

How to print / echo positional parameters index

I have this working and simple code to echo positional parameters VALUES for i do echo "Argument = $i " done Here is the actual output from the scrip Argument = --atleast-pkgconfig-version Argument ...
6
votes
5answers
810 views

Using parameter substitution on a Bash array

I have file.txt that I need to read into a Bash array. Then I need to remove spaces, double quotes and all but the first comma in every entry. Here's how far I've gotten: $ cat file.txt 10,this 2 0 ...
8
votes
1answer
438 views

Pass associative array as parameter list to script

In a script I have an associative array like: declare -A my_vars=( ["key1"]="value1" ["key2"]="value" ) Is there a single command to transform that into a parameter list in the form --key1=value1 --...
-1
votes
1answer
46 views

Shell Function: Sequence of Pipelines as Argument

I have a shell function (in .bashrc) which creates a temp file, executes the arguments (including all sequence of pipelines), redirects it to a temp file and then open it in VS Code. I invoke the ...
0
votes
1answer
261 views

Bash: Error in assigning default value to a variable

Inside my bash script: This works: CWD="${1:-${PWD}}" But, if I replace it with: CWD="${1:=${PWD}}" I get the following error line #: $1: cannot assign in this way Why I can't assign to ${1}?
0
votes
2answers
63 views

how to pass argument to shell and check if argument is not empty

i have this little piece of code lets say get.sh that sets the date into a variable like this date=$(date +%b%d%y) now I want to be able to pass custom date parameter to get.sh like ./get.sh --...
2
votes
1answer
91 views

How may I echo all but the last parameter in bash?

I have the following #!/bin/bash function f1 () { echo "${@:1:-2}" } f1 1 2 3 4 5 6 I need to echo 1 2 3 4 5 man bash tells me that when I use @ I can't use a negative length. I resorted to using ...
5
votes
1answer
642 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 ...
-1
votes
1answer
223 views

sh shell: how to use $1 inside quotes

I am using this code: #!/bin/sh if [ $# -lt 2 ] then echo "wrong syntax" echo "ct_cmp.sh <label1> <label2> [<file_extension>]" else if [ $# -eq 2 ] then ...
1
vote
2answers
94 views

Removing digits from beginning of filename [duplicate]

I was hoping this would work: $ find . -type f -exec basename {} \; | while EFS= read -r f; do echo "${f##[0-9]}"; done But, for example, for files named as: 1foo 11bar it returns: foo ...
0
votes
1answer
163 views

How to use parameter expansion with find -exec {}? [duplicate]

I want to incorporate something like: for f in */*; do mv "$f" "${f%/*}/foo.${f##*.}"; done Into my find x -exec y {} \;-style workflow. The for loop construct & "$f" variable will ...
1
vote
3answers
73 views

Is there a way to protect a file in any way so that other superusers CANNOT modify, delete or overwrite it?

When entering a sudo command file is there a way to set a parameter(s) which locks the file afterward so it cannot be modified, deleted, or overwritten by any other superusers? More specifically: I ...
0
votes
1answer
24 views

Pass parameter to a different bash shell

I have written a bash script Script1.sh #!/bin/sh read -p "Enter name of the document file :" name read -p "Enter LHOST :" lhost read -p "Enter LPORT :" lport echo "use exploit/...
1
vote
2answers
904 views

Handling unused getopts argument (are options not mandatory?)

I have a script that starts with getopts and looks as follows: USAGE() { echo -e "Usage: bash $0 [-w <in-dir>] [-o <out-dir>] [-c <template1>] [-t <template2>] \n" 1>&2;...
0
votes
2answers
27 views

How to pass in log file creation to pass in to script to attach the file

I have several cron jobs I run to back up dbs: 0 8 * * * BACKUP=DEV DB=01 /usr/local/bin/backup.sh > /var/log/backup-db01-`date "+\%m\%d\%y"`.log 2>&1||/usr/local/bin/create-ticket.sh 0 16 ...
1
vote
1answer
437 views

How does FIO benchmark set IOdepth?

NOTE: My question stems from this other U&L Q - What exactly is iodepth in fio? I want to know how internally FIO sets I/O depth. I.e., one of the parameters we submit to FIO when we run it is "...
0
votes
1answer
60 views

Create custom parameters (options) for already existing commands?

Recently I 've been wanting to create a custom parameter for pacman. To elaborate, I have tweaked pacman.conf so that specific packages (linux, linux-firmware, and a couple more) are ignored when I ...
3
votes
3answers
387 views

Parameters passed to a sourced script are wrong

A script on AIX which checks the number of parameters passed and complains if they are not correct:- if [ "$#" -ge 1 ]; then ... else echo 'Usage: myscript <a> [b] [c]' fi The script sets ...
3
votes
2answers
75 views

How to pass a search pattern starting with $ to less on the command line

I just tried to pass a search pattern starting with $ to less: less +/'\$l' myfile.pl and I got There is no -l option ("less --help" for help) After reading the manual, I tried the alternate -p-...
0
votes
1answer
101 views

How to pass variable values to a script and run it in one line?

I have a file (temp_4n.in) with the following lines: 5 C 172.0696 5 C 135.6942 5 H 30.9062 5 H 31.8124 12 H 31.0377 12 O 293.0612 12 H 32.4678 I have a script (...
1
vote
2answers
111 views

parameter operation inside awk line

When I run bjobs -w in the machine where I work, I get the next output: JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME 821213 user1 RUN parallel16 hpc2 16*...
4
votes
1answer
973 views

Is bash special parameter $@ treated as a loop in printf?

So I am testing the following: foo() { printf "\nAll the parameters, each on a separate line:\n" printf "param: %s\n" "$@" } foo The "nicely colored" rainbow The output is: All the ...
1
vote
1answer
35 views

Why does substring expansion [ test=“-efoo”; echo ${test:0:2} ] fail?

On Linux Mint, using bash.. test="-ffoo"; echo ${test:0:2} works outputting the first two characters but test="-efoo"; echo ${test:0:2} fails, with apparently null output. I'm thinking the form ...
1
vote
3answers
442 views

Use of positional parameters inside function defintion

How to use the positional parameters which are given from the command line in a function definition?because inside the function definition ,$1 and $2 mean the values that are input to it!
0
votes
1answer
989 views

Syntax error near unexpected token `}' in a Bash function with an if-then statement [closed]

I stored the following script in a file and created an alias to that file in the user's bashrc, then sourced that bashrc: #!/bin/bash domain="$1" && test -z "$domain" && exit 2 ...
0
votes
2answers
73 views

How to use param values inside for loop

I am running my script as script.sh 12345 12346 12347 for z in 1..$(seq 1 $#); do echo "param $z is $($(echo $z))"; //Line 4 done; I am expecting output as below: param 1 is 12345 param 2 is ...
0
votes
0answers
42 views

What is the meaning of “#nnnnnnnnnnnn” in GNOME terminal configuration file?

The file ~/.gconf/apps/gnome-terminal/profiles/Default/%gconf.xml contains: <?xml version="1.0"?> <gconf> <entry name="use_theme_colors" mtime="1517920383" type="bool" value="...
9
votes
9answers
4k views

Bash: Extract one of the four sections of an IPv4 address

We can use the syntax ${var##pattern} and ${var%%pattern} to extract the last and first section of an IPv4 address: IP=109.96.77.15 echo IP: $IP echo 'Extract the first section using ${var%%pattern}: ...
2
votes
0answers
56 views

Bash: Special variables $@ vs. $* in For Loop [duplicate]

Using $@ instead of $* would preserve quoting. Consider the following script: #!/bin/bash # Test.sh for arg in $@ do echo "I found the argument $arg" done ./Test.sh "One Two Three" I reach the ...
5
votes
3answers
2k views

Is there a way to get the positional parameters of the script from inside a function in bash?

The following variables are used to get the positional parameters: $1, $2, $3, etc. $@ $# But they are used for both positional parameters of the script and the positional parameters of a function. ...
21
votes
2answers
2k views

command line terminology: what are these parts of a command called?

At the command line I often use "simple" commands like mv foo/bar baz/bar but I don't know what to call all the parts of this: ┌1┐ ┌──2───┐ git checkout master │ └──────3──────┘ └───────4─────────...
4
votes
2answers
385 views

How to output an individual element of “$@”?

I have read that $@ is an array that holds the positional parameters. I have tried to output an element of the $@ array: echo ${@[1]} But bash is giving me this error: test.sh: line 1: ${@[1]}: ...
4
votes
3answers
2k views

Why $0 is not a positional parameter?

I have read that positional parameters start at $1 (for example: $1, $2, $3 and so on are positional parameters). But $0 is not a positional parameter. But why $0 is not a positional parameter? I ...
1
vote
2answers
32 views

Bash - Parameter should not be parsed as bash while outputting

I do have 2 Shell Scripts. The first one triggers the second one and adds some parameters. The second one calls a command and adds the parameters from the first script as parameters for the command. ...
7
votes
1answer
610 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
1answer
563 views

Passing parameters by shell script file to expect script

I need to pass a paramter from a shell script under command line of ssh script for example : #!/usr/bin/expect spawn ssh user@servername.com "cm1+passingparameters.sh;cmd2" my existing script 123....
1
vote
1answer
39 views

What is the correct term for streams we substitute in a parameter?

Consider this code with my parameter: for domain; do cat <<EOF > "/etc/nginx/sites-available/${domain}.conf" My \domain is ${domain}. EOF done Let's break the parameter in ...
1
vote
2answers
107 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-...
3
votes
1answer
245 views

Way to specify param for all commands executed

I was wondering if there is a way to specify a mutual param for X amount of commands. E.g. sudo cmd1 cmd2 cm3 \ --help this obviously doesn't work, but I haven't seen anything in the manual. I'm ...
2
votes
2answers
55 views

Preventing parameter expansion multiple times

I have a code that is writing a script which is writing another script: cat > step1.sh <<-EOF *other commands* cat > step2.sh <<-EOF4 if ...
0
votes
2answers
494 views

what does it mean shell read command line arguments ${1,,}

In the Shell script code, the command line arguments assigned to variable like below. what does it mean comma(,) in the statement. What will be the difference when comma is added twice while reading ...
4
votes
1answer
7k views

Pass an option to a makefile

Makefile my_test: ifdef $(toto) @echo 'toto is defined' else @echo 'no toto around' endif Expected behavior $ make my_test no toto around $ make my_test toto toto is defined ...
0
votes
3answers
134 views

Linux: How do I upgrade ssh-keygen?

I want to make use of the updated version of ssh-keygen because that includes a hashing feature for fingerprints like so: ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub But my current version doesn't ...
5
votes
1answer
249 views

Sed Command behavior difference wrt argument handling

Recently I was working on performing a sed operation on a config file. I found that the sed command is behaving differently with the parameter -ir vs -ri :- [root@node system]# sed -ri 's|(^[[:...
0
votes
1answer
389 views

xargs ignoring 2nd script parameter

I'm calling a bash script with two parameters, let's call them param_one and param_two. I also have a file called test which contains two lines: line_one line_two Here's what my script looks like: ...
2
votes
3answers
1k views

Xargs With Multiple Argument Substitutions - Use environment variable argument after sh -c '…'

This is my command: find $1 -name "*.html" | sort -n | xargs -I {} sh -c 'echo "Dumping file: "{} >> "$2"; w3m {} >> "$2" 2>&1' where: $1 is the path where I will look for files ...