Questions tagged [parameter]
The parameter tag has no usage guidance.
210
questions
1
vote
1
answer
40
views
Splitting parameter list
I want to create a bash function that will accept variable number of parameters. There must be at least one parameter. Then I call another program and need to insert fixed values between the first ...
4
votes
2
answers
140
views
Is it possible to apply substring expansion to all elements of a zsh array?
Let's say I'd like to remove the first two and last three characters from all elements of an array e.g.
results=( QK9H9UtADCgnG AlaLkCADjQ krsxseW8H1VrU 6nBG94ZbCWQ )
I'd like to end up with
results=(...
7
votes
3
answers
599
views
Is it possible to print a command so that the output can be parsed to create the same command?
The question may sound quite complicated, but in fact it is not! Consider:
% f() { echo "$@"; }
% f a
a
% f cmd -o"value with space"
cmd -ovalue with space
% f cmd -ovalue with ...
7
votes
3
answers
448
views
Remove repeating string pattern from variable with POSIX parameter expansion
I wanted to use 2.6.2 Parameter Expansion to remove leading characters from a string, but was surprised to find out that "Remove Largest Prefix Pattern" doesn't automatically repeat the ...
3
votes
2
answers
244
views
Bash Parameter Expansion - Get Variables with a Prefix while Escaping Hyphen
EDIT:
I realized I was mistaken about a central assumption in this post: The ${!prefix@} syntax isn't able to get function names, but only variables. Therefore, there is no way to get ${!prefix@} to ...
0
votes
1
answer
1k
views
Replace $placeholder text in various configuration files with $placeholder parameter
I am at my wits end trying to get sed to do this for me and I feel like an idiot. So I hope someone has a much smarter way to accomplish what seems to be incredibly simple.
file.conf:
USER: !USER!
...
0
votes
1
answer
89
views
Assigning $* in shell script from args array
After iterating thru the shell arguments and filtering out unwanted arguments into an array, I want to assign the array back to $*.
For example, in the below script, I want to remove the arguments -f ...
2
votes
1
answer
210
views
BASH: is it possible to change a prompt of function based on its parameter?
I want to construct a function that will change its user input prompt based on its parameter.
my_fucntion takes 1 parameter as db_host after prompting the user for input:
function provide_host () {
...
1
vote
1
answer
171
views
libvirt nwfilter, multiple parameters
It's possible to pass multiple parameters to the "filterref" using "parameter" keyword. Like this:
<filterref filter='no-ip-spoofing'>
<parameter name='IP' value='10.0....
0
votes
1
answer
131
views
Bash still cut the last part of the third parameter even if I attempted `$*` and `$@`
I have tried the following questions:
Propagate all arguments in a bash shell script
How may I echo all but the last parameter in bash?
I was running docker-compose that checks Dockerfile.
See my ...
0
votes
1
answer
183
views
What is the best way to pass a parameter to a running script?
There is a script (on dash) that runs at system startup (as a daemon). The script is run under root.
From under a user I create a file with the right parameter, and the script checks once a second if ...
1
vote
2
answers
280
views
Please explain the behavior of these parameter expansions using IFS?
I'm trying to figure out how to use the ${parameter%word} expansion with $@ and $*. It started by trying to make a script to combine pdfs using ghostscript, but I ran into some weird behavior with ...
0
votes
0
answers
30
views
korn script printing garbage for param sent to function in utils file
I have a korn util script that isn't receiving correct parameters. I'm not sure why. I'm new to korn, and searching for the issue online didn't help.
I execute the calling script this way from ...
0
votes
0
answers
78
views
Why does piping input to a Bash function prevent assignment to a local nameref variable? [duplicate]
Given Bash 5.0.17 and the function
function assign_greeting {
local -n output_var=$1
output_var=$(cat)
}
why does echo $GREETING in
$ echo Hello | assign_greeting GREETING
$ echo $GREETING
$
...
4
votes
2
answers
829
views
Zsh use an array in a find command
I would like to rsync over a few files, specified with an array, and delete any other file in a directory.
The only approach I can think of is to remove other files using find, and rsync over the ...
0
votes
1
answer
623
views
How to retrieve items from an array of arrays?
Hello StackExchange pros!
I am working on a zsh project for macOS. I used typeset to create three associative arrays to hold values, and a fourth array to reference the individual arrays. Is it ...
1
vote
1
answer
161
views
Zsh: How to make `${x:?}` return non-zero in case of empty `$x`?
How to make ${x:?} return non-zero in case of empty $x? By default, it exits the shell (subshell in this example) with 0.
function sth() {
local url="${1:?}"
...
}
(sth) ; echo $? # ...
1
vote
1
answer
1k
views
How to pass variable arguments to expect
I want to pass a variable number of arguments to a expect script:
#!/usr/bin/expect
set timeout 10
spawn ssh -o "StrictHostKeyChecking no" [lindex $argv 0]@[lindex $argv 2]
expect "...
0
votes
0
answers
63
views
The IF statement parameter dimensional x in BASH script [duplicate]
I have found this in an old script but can't tell what is the use of the "x" infront of the ${VARIABLE} and infront of the value "onx" being compared
VARIABLE="${VARIABLE:-&...
0
votes
2
answers
987
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....
1
vote
0
answers
63
views
Bash: Parameter Expansion | Parameter Transformation on List of Assoc.Array Keys
Is this possible(bash v5.0.3)?
I'd like to dynamically populate a select list using the keys of an associative array (for further code reuse & script automation). Some keys simply require ...
0
votes
0
answers
37
views
Shell script getopts weird behaviour args not parsing
I'm trying a simple shell script to get the arguments passed by the user, but cannot seem to find my error. Sometimes it works, but mostly not (weird).
helpFunc()
{
echo ""
...
0
votes
0
answers
15
views
Passing a parameter with quotes to a shell script [duplicate]
I have a useful script greplog that does:
grep -Eh --color $1 /var/log/apache2/other_vhosts_access.log{.1,}
so I can easily search like this:
greplog index.php
But
greplog "POST /test.php"
...
4
votes
6
answers
2k
views
Command parameters & arguments - Correct way of typing?
Which is the correct way - to separate the argument from the parameter with a whitespace, or no?
And should you separate arguments or stick them all together?
Examples:
<command> -D 192.168.0....
11
votes
3
answers
13k
views
How to pass all arguments of a function along to another command?
Hello I have this in my ~/.bash_profile
export GOPATH="$HOME/go_projects"
export GOBIN="$GOPATH/bin"
program(){
$GOBIN/program $1
}
so I'm able to do program "-p ...
3
votes
1
answer
312
views
Indirect parameter expansion in associative array
Following this answer, I want to apply the approach on my script. The basics of it is:
foo="bar"
baz="foo"
echo "${!baz}"
bar
I want to provide translated strings, like ...
1
vote
1
answer
384
views
Remove the first parameter in $*
I've got a small "logit" script;
#!/bin/bash
echo "• $(date +%Y.%m.%d.%H.%M.%S) • " >> "$1"
printf "%s" "$*" >> "$1"
This way I ...
7
votes
3
answers
595
views
Most robust way to list every basename in a directory, sorted by modification date?
Given a directory containing:
note 1.txt, last modified yesterday
note 2.txt, last modified the day before yesterday
note 3.txt, last modified today
What is the best way to fetch the array note 3 ...
0
votes
4
answers
2k
views
Find xml tag and replace the text inside the tag to a parameter value multiple occurrences
Find a specific xml tag and replace the text inside tags to some parameterized value. Multiple occurrences need to be replaced.
Sample file content:
<a>abc</a>
Current attempt:
sed -i &...
0
votes
2
answers
727
views
how can i detect user input is coming from pipe line or with parameters? (as using "if else")
how can i detect user input is coming from pipe line or with parameters? (as using "if else")
example:
with pipeline
$ cat input_file | ./example.sh
hello
world
with parameters
$ ./example.sh "...
0
votes
1
answer
418
views
How do I delete the lines in a range that contain a given string from a script?
I believe the title is self-explanatory.
I have some files given as parameters and the given string is the last parameter of my script.
I have tried the two scripts below and do not know how I could ...
0
votes
1
answer
384
views
Passing custom parameter from GRUB to the OS
My program, wich is bash scripts, runs in a custom ISO with Debian.
I want a GRUB menuentry that passes a parameter from GRUB to the OS, a debugging flag, so I can test the program, and at the same ...
0
votes
1
answer
30
views
Processing parameters with * passed to unix [duplicate]
I am receiving a query via a configuration file in unix, for ex. Config file content will be in the format:
Table_name|query
ABC|select ABC.A,ABC.B from PQR left join (select * from ABC) on ABC.pk=...
2
votes
2
answers
7k
views
How does the tftpd-hpa --verbosity option work?
I'm trying to set up a TFTP server using tftp-hpa, and according to the manpage I can use the --verbosity option to get more output.
Unfortunately I can't find anything that explains what I should ...
0
votes
0
answers
97
views
Shell scripting parameters
I have the following script. I want the inputs to be: -a, -l, -s <number>, -c <keyword>, -d <keyword> -b/-r, -n. However, there's a problem with the number and keyword parameter as ...
1
vote
1
answer
1k
views
Apply multitail's filtering to many files passed via wildcard
multitail has a nice regex-based filtering mechanism that is described in the manpage and online manual. Both sources state that log lines matching a given regex can be excluded from output using the -...
5
votes
2
answers
702
views
Customize sysctl parameters by user
I know there's *.conf file in /usr/lib/sysctl.d and/or /etc/sysctl.d folders ready to establish kernel parameters on boot. But they are general;
what I want is to customize some of these parameters (...
0
votes
0
answers
94
views
How is it possible to call CwRsync.exe via a Bash Script with variables and arguments?
This is the commandline currently used to call Rsync that's part of Cygwin 64 install.
rsync -aqHPR $CygSrcRoot/./$FolA1 $CygSrcRoot/./iMazing.Versions/Versions/$FolA1 $CygDstRoot/$DstCountFol --...
0
votes
1
answer
1k
views
Why arguments which passed to .sh file are missing after sudo su?
I need to run .sh file on my server from my local machine.
I could do it using below command.
ssh -p my_port_no -i path_to_key user@ip_address "bash -s" < testOnServer.sh
Now I need to pass some ...
2
votes
1
answer
360
views
Parsing an array as one of many keyword parameter in a bash script
I have a bash script (script.sh) that takes in many parameters in the format --keyword value. It is read in when the script is invoked with the following lines:
# Get our arguments using flags,
while ...
4
votes
1
answer
423
views
What is the historical reason for using curly braces {} as placeholder in find -exec
Everyone knows find . -exec foo {} \; and at some point stopped thinking about it. But recently I came back to the question that arose when I first learned it:
Why would anyone choose {} as the ...
2
votes
2
answers
6k
views
Check mandatory argument of parameters
I have script with several parameters that have required argument:
while [ "$1" != "" ]; do
case $1 in
-f | --first ) shift
first=$1
...
3
votes
1
answer
263
views
How to deal with optional input in shell script?
My assignment task is to print n longest lines from text files. The output is n longest lines with line number and in the same order as in the original file. For example, in the original file:
...
0
votes
1
answer
78
views
Start new shell with positional parameters
With Python, I can start a session with positional parameters:
$ python3 - aa
>>> import sys
>>> sys.argv[1]
'aa'
However it does not seem to be possible with shell:
$ sh - aa
sh: ...
1
vote
1
answer
683
views
Variable rsync filter parameters
I have an issue with a variable rsync parameter.
I concat filtered expression on COMPILE_FILTERS variable.
Example :
COMPILE_FILTERS='--filter="- js/editor/editorjs/*"'
rsync -a $COMPILE_FILTERS \
-...
0
votes
1
answer
216
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
1
answer
143
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
1
answer
3k
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
2
answers
686
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
1
answer
759
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 ...