Questions tagged [parameter]
The parameter tag has no usage guidance.
203
questions
0
votes
1
answer
65
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
81
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
246
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
22
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
13
views
How to get only the first n characters of a console-command like openssl rand -base64 14 [duplicate]
How do I get only the first n characters of a console-command like openssl rand -base64 14 (for password creation)
if this was in a variable I could probably use Substring Expansion, but how do I ...
0
votes
0
answers
40
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
$
...
0
votes
0
answers
15
views
SQL script to accept INFILE as parameter?
I have an SQL script, in which some data is being loaded from a file,
something like this:
LOAD DATA local INFILE 'test.csv'
INTO TABLE test ...
Now the path & name of this INFILE is hardcoded ...
4
votes
2
answers
387
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
101
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
78
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 $? # ...
0
votes
1
answer
210
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
23
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
494
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
48
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
33
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
1k
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....
5
votes
2
answers
6k
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
154
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 ...
0
votes
1
answer
53
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
444
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
734
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
321
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
136
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
180
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=...
1
vote
2
answers
4k
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
64
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
870
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
510
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
82
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 ...
1
vote
1
answer
184
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 ...
3
votes
1
answer
324
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 ...
1
vote
2
answers
4k
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
225
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
62
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
494
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
139
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
116
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
2k
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
478
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
368
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 ...
9
votes
5
answers
4k
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 ...
10
votes
1
answer
3k
views
Pass associative array as parameter list to script
In a script I have an associative array like:
declare -A VARS=( ["key1"]="value1" ["key2"]="value" )
Is there a single command to transform that into a parameter list in the form
--key1=value1 --...
-1
votes
1
answer
189
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 ...
2
votes
1
answer
2k
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
2
answers
2k
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
1
answer
384
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 ...
3
votes
1
answer
2k
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 written directly after a command, so what is the definition or phrasing to explain how to distinct them?
In ...