The parameter tag has no usage guidance.
0
votes
1answer
25 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
58 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 ...
4
votes
2answers
615 views
Passing parsed output of sed to find (in this direction)
Well, I think you can find dozens of questions on this platform how to pipe find output to sed, but I haven't found anything for the reverse direction so far. What I want to do is modify my input, and ...
0
votes
1answer
47 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
66 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 \
...
11
votes
2answers
368 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 ...
11
votes
7answers
6k views
Print shell arguments in reverse order
I am a bit stuck. My task is to print the arguments to my script in reverse order except the third and fourth.
What I have is this code:
#!/bin/bash
i=$#
for arg in "$@"
do
case $i
in
...
0
votes
2answers
38 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
68 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)
...
1
vote
1answer
79 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
0answers
98 views
Gummiboot Kernel Parameters, Cannot find /boot/loader dir
I installed Gummi boot to my EUEFI partition which is sda1.
when I do lsblk it show boot is mounted on sda2, which is also my root partition.
when I ls '/boot' there is no loader dir.
I need the ...
0
votes
0answers
24 views
Automated function Logging tool
Is there a automated tool for logging function name , function entry and exit parameters per thread for complex multi threaded application.(C / C++)
0
votes
3answers
76 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 ...
0
votes
0answers
133 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
90 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
164 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: ...
3
votes
3answers
17k views
How do I echo just 1 column of output from ls command?
Lets say when I do ls command the output is:
file1 file2 file3 file4
Is it possible to display only a certain column of output, in this case file2? I have tried the following with no success:
echo ...
1
vote
2answers
288 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
168 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 ...
4
votes
3answers
1k views
How to tell of whether the kernel parameter [passed at command line] is a valid kernel parameter?
In the grub.conf configuration file I can specify command line parameters that the kernel will use, i.e.:
kernel /boot/kernel-3-2-1-gentoo root=/dev/sda1 vga=791 plasticDuck
After booting up a ...
0
votes
2answers
4k 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
286 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
523 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; ...
8
votes
2answers
626 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 ...
1
vote
3answers
54 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 ...
2
votes
2answers
378 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:
...
3
votes
3answers
915 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
123 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:
...
1
vote
2answers
191 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 ...
2
votes
2answers
549 views
Want a seperate file to store mysql username, password, and database name
I have as script that dumps a mysql database, and compresses the file. What I want to do is have another (edit) file which can change the username, password and database name. Then somehow connecting ...
14
votes
4answers
2k 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
...
25
votes
2answers
36k views
How to check if there are no parameters provided to a command?
How do you check if $* is empty? In other words, how to check if there were no arguments provided to a command?
13
votes
2answers
577 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
136 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
92 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
# ...
0
votes
1answer
78 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.
...
2
votes
3answers
153 views
Why are POSIX Find Parameters Different from Other Program styles?
Why is a parameter in the POSIX find command added with a single hyphen for multi-character parameter names, while most other programs use single hyphen to indicate multiple single-character flags, ...
3
votes
1answer
66 views
Customize bash to always include a certain parameter
When using the "ls" command, bash prints in the following format:
file1 file2 file3 file4
file5 file6 file7 file8
But when given the parameter "-1", it prints:
file1
file2
file3
etc...
Is there ...
2
votes
2answers
603 views
What is the bash syntax for extracting the values from multiple instances of the same argument?
I want to use multiple instances of command line paramater such as the -d option used by PHP for passing PHP options. I am currently using the getopts command in bash.
With PHP invocation it would ...
3
votes
2answers
4k views
GRUB2 and kernel vga= parameter
According to the documentation, use of the vga= kernel parameter is deprecated as of GRUB2. The fact that some newer kernels don't seem to support it anymore on certain adapters is of no concern as ...
1
vote
1answer
1k views
What's the right way to set Linux kernel runtime parameters?
What's the prescribed way to set Linux kernel runtime parameters? I've seen sometimes that people will set these in files such as /etc/rc.local.
Is this really the right way to do this?
1
vote
1answer
2k views
Permanently set kernel parameters [isolcpus] without grub?
Is there any way to set kernel parameters in an Ubuntu-based system without relying on grub? (not available in the target environment)
Specifically I want to set the isolcpus parameter to dedicate ...
4
votes
1answer
223 views
Use boot parameter to perform certain actions after boot
I'm asking myself if I can use Grub 2 to tell the Operating System which actions to perform after boot.
Background:
I have a HTPC with Debian Wheezy installed. Sometimes I want to use the System as a ...
0
votes
1answer
201 views
How can I pass in a parameter to sed?
To be more precise - how can I pass in a parameter to a program that then calls sed - how can I 'pass' that parameter along?
I have a file 'source_code.sc'.
I have a sed script "find_expect":
#n
...
2
votes
1answer
135 views
How to manipulate all parameters of a shell script at once?
While for a finite amount of parameters one can explicitly do something like
wrapped_function "${1#prefix}" "${2#prefix}" "${3#prefix}" # etc.,
isn't there a simpler way to manipulate all ...
12
votes
0answers
356 views
Should I use $* or $@? [duplicate]
Which one of $* or $@ is better to use (in array syntax,command line parameters, etc.) to avoid any bugs/problems in code? Or it does not make any difference?
2
votes
1answer
1k views
Execute command supplied by function parameters
I'm trying to create a function method in a bash script that executes a command which is supplied to the method by the paramters.
Meaning somethings like this:
special_execute()
{
# Some code
...
2
votes
1answer
173 views
prevent trap from altering underscore variable $_
I have the following code in my bashrc to get the execution time of the last command from http://stackoverflow.com/a/1862762
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
...
4
votes
2answers
404 views
Why is $# always 0 in my function?
Bash is driving me nuts. I can't figure out why the following (nor any of the dozens of variations I've literally copied and pasted from examples) fails to work:
#!/bin/bash
echo $#
function main {
...
3
votes
1answer
936 views
Bash: slice of positional parameters
How can I get a slice of $@ in Bash without first having to copy all positional parameters to another array like this?
argv=($@)
echo ${argv[@]:2};