The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
2answers
35 views

How can you pass parameters to function in a script?

I'd like to write a function that I can call from a script with many different variables. For some reasons I'm having a lot of trouble doing this. Examples I've read always just use a global variable ...
1
vote
1answer
18 views

How to run pure-ftpd with port range as a service

I am running pure-ftpd on raspbian, I need to pass it parameters to specify the port range for data connections, I read the following page here pure-ftpd faq it mentions that I can run the process ...
0
votes
1answer
20 views

apt - Command line option 'i' [from -info] is not understood in combination with the other options

I was making a shell script with that installs packages from a list. The code looks like this: apps="$(cat ./foo/bar/packages.txt)" apt install $apps But, I get the error E: Command line option ...
2
votes
2answers
58 views

How to assign value to input variable in shell

I am asking user for input and taking input in the variables such as $1, $2 etc. I am checking the variable for null value and wants to replace the value if null. if [ "$2" == "" ]; then 2=value fi ...
0
votes
1answer
37 views

how to properly pass _set_ of parameters with spaces into shell function

My problem is not simple passing parameters with spaces (I know how to achieve that), consider more complicated case: function build() { make CC="$1" CFLAGS="$2" $* # $* is not correct here! } ...
1
vote
1answer
32 views

$* variable of zsh function leads to unexpected results

I have this function (defined inside my ~/.zshrc): function graliases { if [[ "$#*" -lt 1 ]] then echo "Usage: graliases <regex>" else echo "$*" grep -E '*"$*...
1
vote
1answer
60 views

Script to send mail using function

I am trying to write a bash script with a function which you use to send an email from the command line to an address and include a Cc address, a subject line, and an input file. For example, if the ...
0
votes
1answer
90 views

How to use ClamAV to scan the memory

How can I only scan the computer RAM for viruses using the ClamAV command clamscan? I already tried, because I found it on ClamWin forum: clamscan --memory But it seems, that the Linux version ...
1
vote
2answers
40 views

Optional parameters in bash function

I have a function for quickly making a new SVN branch which looks like so function svcp() { svn copy "repoaddress/branch/$1.0.x" "repoaddress/branch/dev/$2" -m "dev branch for $2"; } Which I use to ...
0
votes
0answers
72 views

Kconfig (bool/def_bool/tristate)

In a Kconfig file, what are the differences between : bool def_bool tristate Thank you.
-3
votes
2answers
44 views

Shell with parameters order of entry is the issue

while (("$#")) do opt="$1"; shift; case "$opt" in "-c" | "--create") create_flag=1 ;; "-up" | "--update") update_flag=1 ;; "-q" | "--query") query_flag=1 ;...
0
votes
2answers
124 views

Bash Script execute command as user

I'm just wondering if it's possible to execute a command inside a bash script as a specified user and supply the password in one string. At the moment I have COMMAND="${DIRECTORY}/script.sh" su -c ...
1
vote
2answers
42 views

How do I keep command options from breaking other scripts executed within my command?

I have a bash shell script(my_script.sh) which runs a script(their_script) during execution. My script (my_script.sh) looks like this : THISDIR=`dirname $(readlink -f $0)` main() { cd $THISDIR ...
1
vote
1answer
88 views

Can a bash array be used in place of eval set — “$params”?

I'm taking a look at the optparse library for bash option parsing, specifically this bit in the generated code: params="" while [ $# -ne 0 ]; do param="$1" shift case "$param" in --my-...
1
vote
1answer
63 views

Difference between “-” and “--” prefixed command line parameters? [duplicate]

Scripts on command line offer a wide range of parameters types. Often parameters can be passed to the script via "--[parameter]" or "-[parameter]". But what is the difference? Why do some parameters ...
7
votes
1answer
750 views

Bash alias with a space as a part of the command

I'm trying to create a bash alias, where the alias itself has a space in it. The idea is that the alias (i.e. con) stands for sudo openvpn --config /path/to/my/openvpn/configs/. Which results in a ...
7
votes
2answers
2k views

Count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable)

Brief statement of the question: Is there built-in bash method to count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable), without resorting to ...
1
vote
0answers
28 views

Nested parameter expansion [duplicate]

I know how to use ${parameter#word} Remove matching prefix pattern and ${parameter%word} Remove matching suffix pattern. but is there a way to nest them in a single call, such as ${${variable#...
1
vote
0answers
57 views

How to combine many multitail parameters?

The .multitailrc file contains a color scheme called amir_log, which I load using multitail -cS amir_log ~/wildfly/wildfly-8.2.1.Final/standalone/log/server.log But there are ANSI color codes being ...
3
votes
5answers
462 views

bash iterate file list, except when empty

I thought this would be simple - but it is proving more complex than I expected. I want to iterate through all the files of a particular type in a directory, so I write this: #!/bin/bash for fname ...
15
votes
2answers
669 views

Does parameter order matter with tar? [duplicate]

I am learning Linux. I was surprised to see that the parameter order seems to matter when making a tarball. tar -cfvz casual.tar.gz snapback.txt bucket.txt gives the error: tar: casual.tar.gz: ...
4
votes
1answer
162 views

What does this line in bash do? Parameter-||scriptname

I've been reading through the bash man page, and reading through scripts on my system (CentOS 6.7), looking up things in the bash man page as I go. It's a great exercise; I learned, for instance, how ...
0
votes
1answer
90 views

Expand parameter in quotes in zsh

(Not sure the title is adequate, at least I tried my best…) I want to pass function arguments to zsh’s emulate to evaluate a command in bash emulation: $ .bash() { emulate bash -c "$*" } $ .bash '...
-1
votes
1answer
88 views

script with no arguments should echo a message, but it doesn't [closed]

I'm questioning why my script still does not run the condition when no argument is provided. I think it might be the ordering of my if statements but I'm not sure. Any advice? It doesn't seem to be a ...
1
vote
2answers
140 views

Which are (bash) shell special parameters?

I've found some special parameter with bash starting with $ sign. Example: When I was wandering for exit status I knew about $?, process ID by $$ etc. So, I am sharing this post to know Which are ...
2
votes
2answers
130 views

print empty line in sed output when passing multiple filenames

I'm doing some placeholder replacements in various files that I'm feeding to ldapadd, to add new entries to an LDAP directory: sed \ -e 's/%%FOO%%/whatever/g' \ -e 's/%%BAR%%/other thing/g \ ...
14
votes
2answers
2k views

Correct behavior of EXIT and ERR traps when using `set -eu`

I'm observing some weird behavior when using set -e (errexit), set -u (nounset) along with ERR and EXIT traps. They seem related, so putting them into one question seems reasonably. 1) set -u does ...
0
votes
2answers
47 views

Issue on awk input parameter in ksh

I am running this script: INPUTNAME=ABC.XYZ FILENAME="Sample.xml" awk -v inputName=$INPUTNAME ' /<machine.*name=/ { f=1 ; m=0 ; res="" } f { res = res $0 ORS } f && /...
1
vote
0answers
171 views

Disk configuration options, what can affect performance

I have 2 disks, the same model and vendor, first one , probably performs faster. We do write into multiple files. Can you compare 2 configurations and tell what can affect performance? 1. (faster) *-...
2
votes
1answer
173 views

find with -exec eval of $0 [duplicate]

In the following command I would like to know why $0 was evaluated to the file found by find and not the echo command. $ find . -type f -perm -u=x -exec bash -c ' /bin/echo $0 is the name of the ...
0
votes
3answers
132 views

Bash: Access parameter passed to last command [duplicate]

This is a situation I often find myself in: mkdir /Some/really/long/path/to/a/directory/ cd /Some/really/long/path/to/a/directory/ I know that ideally you would cd /Some/...etc.../a/ and then mkdir ...
1
vote
0answers
385 views

isolcpus doesn't work on Ubuntu 14

I added isolcpus=0 to the end of the following line to the file /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet splash isolcpus=0" The idea, as I understand it, is to reserve core 0 from having ...
0
votes
2answers
376 views

What is the variable of $#?

I'm learning introductory Linux and came across something which I did not understand: "The following command has been executed: set 10 20 30 40 50 Enter the value of the variable $#: I understand ...
2
votes
2answers
187 views

An error of variable type?

I've an error that I don't understand, it seems that that the problem is that my parameters into the shell are not of the same type as what they are in my SQL Database. For a better understanding: I'...
1
vote
2answers
293 views

How to put $@ in quotes?

My bash script looks like this: #!/bin/bash grep -r --color=always $@ . | nolong The file is saved in /usr/bin/findstr Everything's ok when I run this: findstr hello But when I run this: ...
2
votes
1answer
275 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...
1
vote
2answers
14k views

Convert input string to date in shell script

My shell script: #!/bin/bash echo "$1"; startd=$(date -d "$1" +"%Y%m%d"); echo "$startd"; My command: sudo ./test.sh "20151010" The output: 20151010 20150213 it printed todays date ...
2
votes
3answers
290 views

How can I pass on parameters 4..99 to another function

I'm calling a function and I want to pass up to 100 paramters onto another function. I do not want to pass on the first 3 params, I start with param4 being the first param for the other program. I ...
1
vote
3answers
3k views

How to pass an array to a function as an actual parameter rather than a global variable

Is there a way to pass an array to a function as one of its parameters? Currently I have #!/bin/bash highest_3 () { number_under_test=(${array[@]}) max_of_3=0 for ((i = 0; i<$((${#...
1
vote
3answers
68 views

How to access the contents of a file that is used as an argument when running a bash script?

I am running a bash script with its parameters/arguments as files. From inside the script, how do I get the contents of those files? I run the script with this command line: sh script_name animal....
2
votes
2answers
1k views

Print file name extension using -exec in find

I am playing around with -exec flag of find command. I am trying to use the flag to print the extension name of files, using a fairly new Linux distribution release. Starting simple, this works: ...
4
votes
3answers
2k views

How to pass the content of a file as multiple arguments in bash

I have a file that contains data that gets updated over time (mydata). The file looks like this: 1 2 3 With this file, I want to do this (basically handle each number as a separate parameter): ...
2
votes
1answer
191 views

how handle a path ($1)

I've: /home/wms/mp3/ and /home/wms/tmp/ Inside ~/tmp my script: #!/bin/bash br=64 for a in "$1"*.mp3 ; do ffmpeg -i "$a" -ar 44100 -ab $br "$br""_tmp/${a%.*} ["$br"].mp3" ; done I do: /home/...
1
vote
2answers
349 views

Bash script loop to grow parameters

I want to use whiptail to generate a checkbox list based on the output from another program. Only the first word on each line of the output from the first program is necessary, so I extract it using ...
14
votes
4answers
3k views

What does echo $-1 display?

What does the output of echo $-1, echo $-2, echo $-3.. mean? On one of my Linux boxes, it shows me: echo $-1 imsBEl1 echo $-2 imsBEl2 And on another Linux box, it shows: echo $-1 himBH1 echo $-2 ...
13
votes
2answers
719 views

When running a shell script, is it possible to pass specific positional parameters without having to enter them all in order?

For example, if I have script ./foo that takes 10 parameters, and I only want to pass the 8th parameter. The only way I know how to do this currently is: ./foo '' '' '' '' '' '' '' 'bar' Is there ...
1
vote
2answers
170 views

Shell syntax question with difficult parameter expansion

I am scratching my head to understand this script and can certainly use some expert advice. getopt_simple() { echo "getopt_simple()" echo "Parameters are '$*'" until [ -z "$1" ] do ...
2
votes
1answer
118 views

Parameter substitution and error messages: suppressing line numbers etc

Here is my example file: !/bin/bash # argument-one # Is first argument missing? # First method [[ "$1" == "" ]] && echo "Usage: $(basename $0) filename"; exit 1 # Second method # filename=$...
9
votes
2answers
972 views

Is it possible to use shell parameter variables ($1, …, $@) directly in CLI?

Sometimes it is necessary to emulate and verify the above variables in small examples and then can be copied immediately to some script, etc. I tried to solve by using a simple example in the ...
0
votes
1answer
92 views

Special Parameter query - multiple used to obtain command name? [duplicate]

In a uni text provided us to cover bash scripting, the following variable assignment has got be stumped and I've yet to get an answer back from anyone, hence hopefully someone on here can help. name=$...