The tag has no wiki summary.

learn more… | top users | synonyms

3
votes
1answer
34 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
50 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 ...
1
vote
1answer
73 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
157 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 ...
2
votes
2answers
471 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 ...
0
votes
1answer
96 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
80 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
2answers
337 views

Should I use $* or $@?

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?
1
vote
1answer
133 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
120 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
147 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 { ...
2
votes
1answer
99 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};
2
votes
3answers
101 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, ...
2
votes
2answers
847 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 ...
4
votes
1answer
129 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 ...
2
votes
4answers
192 views

How to write a very simple wrapper that provides default parameters?

Given a program that requires some parameters, e.g. program -in file.in -out file.out, what would be the simple-most approach to write a bash script that could be called with or without any of these ...
3
votes
2answers
211 views

$BASHPID And $$ differ in some cases

I'm reading "BASH pocket guide of Oreilly". It said: The process ID of the current Bash process. In some cases, this can differ from $$. Above explanation , explained $BASHPID variable. ...
3
votes
2answers
146 views

Should stdin or filenames be discarded if both are provided?

grep and sed ignore stdin if you provide a filename parameter: $ echo foo > test.txt $ echo foobar | grep f test.txt foo $ echo foobar | sed -e 's/foo/bar/' test.txt bar Is this established ...
2
votes
2answers
85 views

Parameter expansion seems to be missing a piece

I'm currently learning how to write simple scripts and can't get my head around a very simple problem. I have the following command in my script... touch ${DIRECTORY}/${FILE} This command appears ...
2
votes
2answers
123 views

Parameter splitting

I have a bash script that is a simple wrapper around another process: $ cat ~/bin/s3cmd #!/bin/sh trickle -u 80 ~/bin/s3cmd.py $* $ This works great when the parameters don't contain spaces. ...
4
votes
2answers
224 views

Function caller positional parameters

I need to read and write the positional parameters $@ of a function's caller. The Bash man page says that: A shell function is an object that is called like a simple command and executes a ...
1
vote
1answer
220 views

Is it possible to use a parameter within an alias command [duplicate]

Possible Duplicate: How to pass parameters to an alias? As answered in Can less retain colored output? I want to use git diff --color=always filename | less -r to get a colored output of my ...
4
votes
2answers
356 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 ...
4
votes
3answers
826 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 ...
8
votes
1answer
5k views

How to display kernel command line parameters?

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 After booting a given kernel, is ...
1
vote
2answers
248 views

Transforming positional arguments of a shell script

I'm trying to write a shell script that will transform positional arguments that are passed to it as follows. The shell script passes these arguments to a binary executable (ffigen) which is derived ...
3
votes
2answers
212 views

how to make getopts just read the first character post `-`

I have a shell script testShell.sh which uses getopts as below: #!/bin/bash while getopts ":j:e:" option; do case "$option" in j) MYHOSTNAME=$OPTARG ;; e) SCRIPT_PATH=$OPTARG ;; ...
2
votes
5answers
601 views

Where are command line arguments (e.g. 'some.text') actually passed to?

From what I know, parameters you pass to a command, goes to it's STDIN stream. so this: cut -d. -f2 'some.text' should be perfectly identical to this: echo 'some.text' | cut -d. -f2 as we send ...
2
votes
2answers
527 views

what does Curl's stand-alone hyphen (-) mean?

what's the stand-alone hyphen (between the -C & -O) stand for in this command? curl -C - -O http://www.intersil.com/content/dam/Intersil/documents/fn67/fn6742.pdf FWIW- I'm following a ...
1
vote
1answer
323 views

Passing Command Line Arguments to java From JPackage Script

I installed Rachota -- a time tracking program written in Java -- from the Fedora repo, and yum installed the rachota.jar file to /usr/share/java, but it also created a script at /usr/bin/rachota. ...
3
votes
1answer
159 views

How can I pipe a path to pushd?

This seems like it should be easy enough to do, but I'm clearly not understanding something fundamental about piping output back and forth. I'm trying to do something like this: bundle show ...
4
votes
1answer
301 views

Writing command synopsis in standard man format

I am writing a script and in the usage() function I want to specify the usage. My script uses either option1 or option2 or both. One of them is mandatory. Is there a standard way to write it up?
10
votes
2answers
958 views

What does `:-` mean in a shell script

I saw this in the end of an awesome shell script but I can't understand the login here because I think it's being short-handed for a longer command. spark ${@:-`cat`} This apears at the end of this ...
3
votes
2answers
458 views

Getopts option processing, Is it possible to add a non hyphenated [FILE]?

I'm using getopts for all of my scripts that require advanced option parsing, and It's worked great with dash. I'm familiar with the standard basic getopts usage, consisting of [-x] and [-x OPTION]. ...
5
votes
3answers
2k views

Transform an array into arguments of a command?

I have an array of "options" of a command. my_array=(option1 option2 option3) I want to call this command in a bash script, using the values from array as options. So, command $(some magic here ...
7
votes
1answer
10k 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?
5
votes
4answers
467 views

How can I create a empty file whose name begins with a dash? [duplicate]

How can we create a empty file with the unix name -stuff. It means the name start with -. I tried with touch -stuff but it didn't work.
12
votes
1answer
449 views

How do ${0##*/} and ${0%/*} work?

I'm quite confused about the following regular expressions I found in a shell script: ${0##*/} ${0%/*} How do they work?
2
votes
3answers
239 views

How to substitute awk argument?

I want simplify awk command for common usage so instead of writing awk '{print "rm -r"$4 }' each time I want to write myawk "rm -r"$4. I've tried to write such function myawk() { awk '{ print $1 }' ...
5
votes
3answers
3k 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 ...
3
votes
3answers
2k views

How to pass a string parameter on bash function?

I have this code that does work: get_parameter () { echo "$query" | sed -n 's/^.*name=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" } But I want to replace the "name" with the parameter that I pass ...
3
votes
1answer
200 views

How to unset the positional parameters?

How do I do this: set foo bar baz unset # Something else here echo $# # Should ouput 0 By doing set "", $# will still be 1 and not 0.
11
votes
2answers
1k views

How to safely pass variables to root-enabled scripts?

This question is totally general and not only applicable to my situation, but... I have a small busybox appliance where I want a non-root user to be able to execute a particular script with root ...
3
votes
2answers
1k views

How to escape < or > in a parameter in shell?

I'd like to use grep with a PCRE expression that contains the < character. Bash thinks I want to redirect, but I don't want to. How can I escape <?
2
votes
2answers
238 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 ...
4
votes
2answers
495 views

Documentation of kernel parameters

Where can I find a technical description of the kernel parameters listed in /proc/sys (ob Linux)?
7
votes
5answers
2k views

Indexing and modifying Bash parameter array $@

Is it possible to refer to indexes in $@? I can't find any reference to use like the following anywhere in GrayCat's wiki, and the Advanced Scripting Guide and others assign this to a different ...
24
votes
3answers
5k views

How to pass parameters to an alias?

For bash script, I can use "$@" to access arguments. What's the equivalent when I use an alias?
7
votes
3answers
5k views

How do I split the $0 variable to find directory and relative paths in bash?

The $0 variable contains the path info of the script. How can I change the path info to absolute path? I mean how to process ~, ., .. or similar? How can I split the path info into directory and ...