Linked Questions
15 questions linked to/from Getting the last argument passed to a shell script
6
votes
4
answers
12k
views
Get last parameter on shell script [duplicate]
case 1 :
suppose I am passing a number of parameters to my shell script as follows :
./myshell_script a b c d
and if I run echo $# will give me number of parameters from command line I have passed ...
2
votes
1
answer
843
views
How to get the last parameter in shell [duplicate]
I'm wondering how to obtain the last argument passed to a bash function, like this:
#!/bin/bash
function hello() {
all=$@ # all arguments
n=$# # number of arguments
...
1
vote
1
answer
298
views
How to access directly to the last argument of a function in ash? [duplicate]
To access to the first argument of a function, I use
func() { echo $1; }
How to access directly to the last argument of a function in ash?
I do not want to use loops neither functions or ...
413
votes
21
answers
362k
views
Is there a way to make mv create the directory to be moved to if it doesn't exist?
So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would ...
421
votes
8
answers
136k
views
How can I recall the argument of the previous bash command?
Is there a way in Bash to recall the argument of the previous command?
I usually do vi file.c followed by gcc file.c.
Is there a way in Bash to recall the argument of the previous command?
8
votes
2
answers
1k
views
Get all but first N arguments to a bash function
I'm aware of how to get the last argument passed to a function but I'm wondering how to get all the arguments of a function after the first two:
For instance:
function custom_scp(){
PORT=$1
...
6
votes
2
answers
3k
views
How to get second-to-last argument from previous bash command? (in an interactive bash shell)
How can I easily get the second-to-last (penultimate) word/argument from the previous command in a bash interactive shell? I often run commands in the background, and I would like to get the file ...
1
vote
3
answers
2k
views
bash: How do I identify the filename argument among arguments passed from the command line?
I know if I have a command ./run -c -p '$' -s 10 file.txt
I can write bash script like this
while read line; do
# ...
done < $6
But what if the command may or may not have one/some options, ...
1
vote
2
answers
5k
views
How to process multiple command line arguments in Bash? [duplicate]
I am having problem allowing my script to take more than three arguments. My script will take commands like this, for example:
./myscript.sh -i -v -r filename
so far if it only takes two arguments ...
0
votes
2
answers
568
views
How can I access command line arguments indexed from the end?
How can I get second argument from the end of arguments line in bash?
3
votes
1
answer
499
views
assign last positional parameter to variable and remove it from "$@"
In my /bin/sh script, I need to pass an indeterminate number of positional parameters, and get the last one (assign the last one to variable $LAST) and then remove this last argument from $@
For ...
1
vote
3
answers
499
views
Unix Shell equivalency to Java .hasNext()?
Or anything in shell script to implement the same thing?
I was doing an assignment that requires us to write a Bourne shell script that shows the last argument of a bunch, e.g.:
lastarg arg1 arg2 ...
1
vote
2
answers
206
views
Access second func param when first param is an array in Bash
If I have a bash function with two or more params, and the first is an array, how can I access the second param?
It's the same as this question but the non-array param is the first argument there, ...
0
votes
2
answers
300
views
Finding and Replacing a filename in a css File with Bash script
I want to write a bash script that takes a user input (which will be a filename) and replaces a path to a file inside a css file with that filename. For simplicity, the two files will be in the same ...
-1
votes
3
answers
183
views
In bash how to use the last argument- and adding all other arguments to array
I have a script where the user can add as many arguments as he would like (numbers).
The script will sum all the numbers beside the last number - The last number (argument) is the number that I need ...