Tag Info

New answers tagged

0

I had this issue too and I solved it by using EOF. This is starting a ssh connection to sshserverhost that executes test.sh with parameter $HOSTNAME on the remote server (sshserverhost). at now + 1 minutes <<EOF ssh -t sshserverhost 'bash -s' <~/test.sh $HOSTNAME EOF


-1

There are two different concepts: mandatory vs optional arguments, and options vs operands. Options are arguments that start with -, operands are arguments that don't start with - and aren't the argument of an option. Options are identified by their name and can normally be in any order. Operands are identified by their position. So in someprogram -a -z -c ...


2

If you're fine with the optional arguments being at the end, you can just do this: foo=$1 bar=$2 baz=${3:-default value} That will store the first two arguments in $foo and $bar. If a third argument was provided, it will be stored in $baz; otherwise it will default to default value. You can also just check if the third variable is empty: if [ -z "$3" ]; ...


3

echo "*file 2" | grep -o ^. prints *. Since you have a command substitution outside double quotes, it undergoes globbing (a.k.a. wildcard matching a.k.a. filename generation) and word splitting. If the current directory is not empty, * expands to the list of files in the current directory. Each file becomes one token in the [ command, which is highly likely ...


1

The number of arguments is in the parameter $#. if [ $# -ne 2 ]; then echo 1>&2 "Usage: $0 DIRECTORY1 DIRECTORY2" exit 3 fi If you want to enforce that the arguments are both directories (as opposed to other types of files), test them with -d. The utility diff compares two files. With the option -r, it compares directories recursively. diff ...


4

Processing arguments Processing arguments that are passed via a script's command line is as simple as follows. Say we had this script: $ cat cmd.bash #!/bin/bash echo "arg1: $1" echo "arg2: $2" Now run with no arguments: $ ./cmd.bash arg1: arg2: With 1 argument: $ ./cmd.bash hi arg1: hi arg2: With 2 arguments: $ ./cmd.bash hi bye arg1: hi ...


2

Most commands can deal with input that's either a file that they need to open for input, or as a stream of data that's passed to the command via STDIN. When the contents of cat file.txt is sent to another command through a pipe (|) the output via STDOUT that's passed to the pipe on the left side, is setup and fed to the command that's on the right side of ...


6

Aliases don't handle arguments. Define a function: myfunc () { /dir1/dir2/dir3/dir4/executable "$1" fixed-argv2 fixed-argv3 }


1

A POSIX shell has a single array: the positional parameters ($1, $2, …), collectively accessed as "$@", and set with the set -- builtin. More precisely, there is one array per function instance on the current call stack, but only the array of positional parameters of the currrent function (or of the script, if outside any function) is accessible at any ...


3

With grep would you not want to make use of the -f or -F switches that grep offers? From the grep man page: -F, --fixed-strings Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by POSIX.) -f FILE, --file=FILE Obtain patterns from FILE, one per line. ...



Top 50 recent answers are included