0

I downloaded a open-source package and make. But error happens when I run the admin script trying to begin. I have found it was some problem about the path.But there's still some problem confused me:

#! /bin/bash

# ionadmin - temporary wrapper script for .libs/ionadmin
# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.7ubuntu1
#
# The ionadmin program cannot be directly executed until all the libtool
# libraries that it depends on are installed.
#
# This wrapper script should never be moved out of the build directory.
# If it is, it will not operate correctly.

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
sed_quote_subst='s/\([`"$\\]\)/\\\1/g'

# Be Bourne compatible
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
  emulate sh
  NULLCMD=:
  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else
  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
fi
  1. sed_quote_subst: what a value it has? due to the existing of '', some meta in '' are disabled . But I don't know which are them.
  2. #!/bin/bash & zsh emulate: The first line declare that this script is running in bash. So, why there is a emulate, which is from zsh?
  3. alias -g '${1+"$@"}'='"$@"': I just input this on another bash and get the error: -g :invalid option, I'm confused about the difference of zsh & bash, and how they work together. Could you explain it to me, please?

I'm a new hand for this , so this question may not be that "useful" to you. But your answer can help me better understand this world.

muru
  • 197,895
  • 55
  • 485
  • 740
Frank Wang
  • 207
  • 2
  • 10
  • if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then echo "Does the run in bash?"; else echo "The else statement runs in bash"; fi – Erik Johansson Oct 18 '15 at 07:20
  • You need to state what is wrong, what error message do you get etc. – Erik Johansson Oct 18 '15 at 07:24
  • @ErikJohansson THX . I just was confused about it and the error is not important , because now I was tripped by this : http://askubuntu.com/questions/399444/zsh-man-page-documentation-missing-in-packages – Frank Wang Oct 18 '15 at 07:40

2 Answers2

1
  1. #!/bin/bash & zsh emulate: The first line declare that this script is running in bash. So, why there is a emulate, which is from zsh?

The first line, the shebang, only indicates that if the script is executed directly, it would be run using bash. Nothing prevents you from running it using zsh:

zsh admin.sh

I don't know why the author thought to test for zsh, but they did. This section of code is for zsh, and won't run in bash:

emulate sh
NULLCMD=:
# Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
# is contrary to our usage.  Disable this feature.
alias -g '${1+"$@"}'='"$@"'
setopt NO_GLOB_SUBST
  1. alias -g '${1+"$@"}'='"$@"': I just input this on another bash and get the error: -g :invalid option, I'm confused about the difference of zsh & bash, and how they work together. Could you explain it to me, please?

That's a very broad question. I won't explain all the differences of zsh and bash - go read the documentation of both for that. For the specific point of alias -g, zsh has global aliases. In bash, aliases are only substituted at the start of the line. In zsh, alias -g defines global aliases which are substituted everywhere in the line.

So, in zsh, if I do:

alias -g foo=bar

And then run:

echo foo

The output will be:

bar
muru
  • 197,895
  • 55
  • 485
  • 740
0

Your questions lacks info, but I'll try to answer it like this:

  1. sed regexp demystify

    s/\([`"$\\]\)/\\\1/g'
    ^     ^         ^----------------- with The character with a leading \
          | 
    |     | --- the characters `"$\
    |
    |-- replace
    

    So " becomes \"

  2. I have no idea, zsh isn't my cup of tea when you are running scripts.

  3. Test if statements like this:

    if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then 
         echo "Does the if statement run in my shell?"; 
    else 
         echo "The else statement runs in my shell"; 
    fi