Tag Info

New answers tagged

0

I stole this from drupal.org, but you could do something like this: while [ $# -gt 0 ]; do case "$1" in --p_out=*) p_out="${1#*=}" ;; --arg_1=*) arg_1="${1#*=}" ;; *) printf "***************************\n" printf "* Error: Invalid argument.*\n" printf "***************************\n" exit 1 esac ...


2

In your scenario, command is reading from its standard input; unless it accepts some other way of providing this information, you need to continue feeding it its input in this way. So if you don't want to use a file, use printf with a pipe: printf "To: me@domain.com\nMessage: Some message" | command


1

You could source a configuration file. In your script you can do: #!/bin/sh #... CONFIG="${HOME}/myconfig" DB_USER="" DB_PWD="" if [ -f "${CONFIG}" ] then . "${CONFIG}" fi #... which sources (reads and executes commands from) a configuration file myconfig in your home directory, if present with the dot operator. Content of the myconfig file: ...


0

If you store the credentials in a file like this: SCHEMA:DB_USER:DB_PWD then you can do: eval $(grep "^$SCHEMA:" credentials-file | awk -F : '{print "DB_USER=" $2 "; DB_PWD=" $3}') From then on you can use $DB_USER and $DB_PWD. Note that this assumes there are no special characters in either DB_USER or DB_PWD field, i.e. characters that are special to ...


0

It is tempting to try getopt order known options up front. Unfortunately, it rejects all unknown arguments and stops parsing immediately. But, as long as long options are not overly complex, bash's getopts can be tricked to do this. Some inspiration was taken from mkaurball. Caveats follow below the source. #!/bin/bash while [ $OPTIND -le $# ] do if ...


1

I don't think that there's a standard method (i.e. besides implementing it all from scratch) that would be available, let alone widely availabe in shells. Though ksh supports a quite powerful getopts built-in. Based on this (and on your quite demanding requirements) I outlined a possible ksh based solution with the following code fragment: while getopts ...


0

This might works : #!/bin/bash su - user2 -c 'echo "$0" "$@"' -- "$@" Use simple quotes ' to pass the command argument to su so you don't have to escape the double quotes ". References : Escaping bash function arguments for use by su -c - Stack Overflow bash - Passing arguments to su-provided shell - Unix & Linux Stack Exchange



Top 50 recent answers are included