org.kde.koala
Class KShell

java.lang.Object
  extended by org.kde.koala.KShell

public class KShell
extends java.lang.Object

\namespace KShell Provides some basic POSIX shell and bash functionality.

See Also:
KStringHandler

Field Summary
static int AbortOnMeta
           
static int BadQuoting
           
static int FoundMeta
           
static int NoError
          Status codes from splitArgs()
static int NoOptions
          Flags for splitArgs().
static int TildeExpand
           
 
Constructor Summary
KShell()
           
 
Method Summary
static java.lang.String homeDir(java.lang.String user)
          Obtain a user's home directory.
static java.lang.String joinArgs(java.lang.String[] args)
          Quotes and joins args together according to POSIX shell rules.
static java.lang.String joinArgsDQ(java.lang.String[] args)
          Same as above, but $'' is used instead of '' for the quoting.
static java.util.ArrayList splitArgs(java.lang.String cmd)
           
static java.util.ArrayList splitArgs(java.lang.String cmd, int flags)
           
static java.util.ArrayList splitArgs(java.lang.String cmd, int flags, int[] err)
          Splits cmd according to POSIX shell word splitting and quoting rules.
static java.lang.String tildeExpand(java.lang.String path)
          Performs tilde expansion on path. Interprets "~/path" and "~user/path".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NoOptions

public static final int NoOptions
Flags for splitArgs().

See Also:
Constant Field Values

TildeExpand

public static final int TildeExpand
See Also:
Constant Field Values

AbortOnMeta

public static final int AbortOnMeta
See Also:
Constant Field Values

NoError

public static final int NoError
Status codes from splitArgs()

See Also:
Constant Field Values

BadQuoting

public static final int BadQuoting
See Also:
Constant Field Values

FoundMeta

public static final int FoundMeta
See Also:
Constant Field Values
Constructor Detail

KShell

public KShell()
Method Detail

splitArgs

public static java.util.ArrayList splitArgs(java.lang.String cmd,
                                            int flags,
                                            int[] err)
Splits cmd according to POSIX shell word splitting and quoting rules. Can optionally perform tilde expansion and/or abort if it finds shell meta characters it cannot process.

Parameters:
cmd - the command to split
flags - operation flags, see Options
err - if not NULL, a status code will be stored at the pointer target, see Errors
Returns:
a list of unquoted words or an empty list if an error occurred

splitArgs

public static java.util.ArrayList splitArgs(java.lang.String cmd,
                                            int flags)

splitArgs

public static java.util.ArrayList splitArgs(java.lang.String cmd)

joinArgs

public static java.lang.String joinArgs(java.lang.String[] args)
Quotes and joins args together according to POSIX shell rules.

Parameters:
args - a list of strings to quote and join
Returns:
a command suitable for shell execution

joinArgsDQ

public static java.lang.String joinArgsDQ(java.lang.String[] args)
Same as above, but $'' is used instead of '' for the quoting. The output is suitable for splitArgs(), bash, zsh and possibly other bourne-compatible shells, but not for plain sh. The advantage is, that control characters (ASCII less than 32) are escaped into human-readable strings.

Parameters:
args - a list of strings to quote and join
Returns:
a command suitable for shell execution

tildeExpand

public static java.lang.String tildeExpand(java.lang.String path)
Performs tilde expansion on path. Interprets "~/path" and "~user/path".

Parameters:
path - the path to tilde-expand
Returns:
the expanded path

homeDir

public static java.lang.String homeDir(java.lang.String user)
Obtain a user's home directory.

Parameters:
user - The name of the user whose home dir should be obtained. An empty string denotes the current user.
Returns:
The user's home directory.