Questions tagged [parameter]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
20 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
21 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=...
0
votes
1answer
65 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
42 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 ...
0
votes
1answer
51 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
157 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
19 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
125 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 ...
0
votes
0answers
17 views

Ram buffer from network transfers, what parameters determine it?

Firstly, I'll qualify my statements. I've been told that network transfers are buffered through ram when using Linux. So, if i have for example, an unraid server which from what I understand is a ...
1
vote
1answer
29 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 ...
0
votes
0answers
50 views

Passing variable into shell [duplicate]

I'm a newbie in shell scripting. I need to pass a parameter into a shell script when I execute it: ./test.sh 1234 In my script I would like to assign 1234 into a variable, how do I do it?
2
votes
0answers
65 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 ...
0
votes
2answers
484 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
109 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
50 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: ...
0
votes
1answer
96 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
60 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
57 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
406 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
134 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
108 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 ...
8
votes
5answers
2k 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
1k 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
77 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 ...
1
vote
1answer
734 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
423 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
105 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 ...
4
votes
1answer
1k 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 ...
-1
votes
1answer
678 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
341 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
510 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
94 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
29 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
3k 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
39 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
714 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
117 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 ...
4
votes
3answers
960 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
155 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
307 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
222 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
1k 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
40 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 ...
2
votes
3answers
849 views

Use of positional parameters inside function defintion

How do I use the positional parameters (which are given from the command line) inside of a function declaration? When inside the function definition, $1 and $2 are the only the positional parameters ...
0
votes
1answer
2k 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
91 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
54 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
10answers
5k 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
75 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 ...