Questions tagged [parameter]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 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
2answers
106 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
0answers
14 views

bash: execute command inside bash parameter expansion [duplicate]

Is it possible, to turn this into a one-liner with a nested expression? simpler put: stuffing the first line into the second. scriptPath="$(readlink -f ${BASH_SOURCE[0]})" containerDir=${...
0
votes
1answer
40 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
1answer
36 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
1answer
37 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
0answers
19 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
2answers
72 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
0answers
36 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
0answers
24 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
0answers
14 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" ...
5
votes
6answers
907 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
2answers
2k 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
1answer
72 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
1answer
24 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 ...
6
votes
3answers
370 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
3answers
321 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
2answers
115 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
1answer
70 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
1answer
107 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
1answer
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
2answers
2k 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
0answers
49 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
1answer
499 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
2answers
379 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
0answers
61 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
1answer
836 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
1answer
77 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
1answer
231 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
2answers
3k 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
1answer
193 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
1answer
58 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
1answer
327 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
1answer
89 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
98 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
1k 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
374 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
220 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
5answers
3k 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 ...
9
votes
1answer
2k 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
1answer
132 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
1answer
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
2answers
1k 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
263 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
1answer
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 ...
0
votes
1answer
1k 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
904 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
1k 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
199 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
35 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/...