org.apache.hadoop.util.Shell.bashQuote()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.apache.hadoop.util.Shell.bashQuote()方法的一些代码示例,展示了Shell.bashQuote()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Shell.bashQuote()方法的具体详情如下:
包路径:org.apache.hadoop.util.Shell
类名称:Shell
方法名:bashQuote

Shell.bashQuote介绍

[英]Quote the given arg so that bash will interpret it as a single value. Note that this quotes it for one level of bash, if you are passing it into a badly written shell script, you need to fix your shell script.
[中]引用给定的arg,以便bash将其解释为单个值。请注意,这引用了一个级别的bash,如果要将其传递到一个写得不好的shell脚本中,则需要修复shell脚本。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Returns a command to run the given script.  The script interpreter is
 * inferred by platform: cmd on Windows or bash otherwise.
 *
 * @param script File script to run
 * @return String[] command to run the script
 */
public static String[] getRunScriptCommand(File script) {
 String absolutePath = script.getAbsolutePath();
 return WINDOWS ?
  new String[] {"cmd", "/c", absolutePath }
  : new String[] {"bash", bashQuote(absolutePath) };
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * A command to get a given user's group id list.
 * The command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 * This command does not support Windows and will only return group names.
 */
public static String[] getGroupsIDForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]{getWinUtilsPath(), "groups", "-F", "\"" + user +
             "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -g " + quotedUser + "; id -G " +
             quotedUser};
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * A command to get a given user's groups list.
 * If the OS is not WINDOWS, the command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 */
public static String[] getGroupsForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]
    {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -gn " + quotedUser +
             "; id -Gn " + quotedUser};
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/** Return a command to send a signal to a given pid. */
public static String[] getSignalKillCommand(int code, String pid) {
 // Code == 0 means check alive
 if (Shell.WINDOWS) {
  if (0 == code) {
   return new String[] {Shell.getWinUtilsPath(), "task", "isAlive", pid };
  } else {
   return new String[] {Shell.getWinUtilsPath(), "task", "kill", pid };
  }
 }
 // Use the bash-builtin instead of the Unix kill command (usually
 // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported
 // OSes.
 final String quotedPid = bashQuote(pid);
 if (isSetsidAvailable) {
  return new String[] { "bash", "-c", "kill -" + code + " -- -" +
    quotedPid };
 } else {
  return new String[] { "bash", "-c", "kill -" + code + " " +
    quotedPid };
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Returns a command to run the given script.  The script interpreter is
 * inferred by platform: cmd on Windows or bash otherwise.
 * 
 * @param script File script to run
 * @return String[] command to run the script
 */
public static String[] getRunScriptCommand(File script) {
 String absolutePath = script.getAbsolutePath();
 return WINDOWS ?
  new String[] {"cmd", "/c", absolutePath }
  : new String[] {"/bin/bash", bashQuote(absolutePath) };
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Returns a command to run the given script.  The script interpreter is
 * inferred by platform: cmd on Windows or bash otherwise.
 * 
 * @param script File script to run
 * @return String[] command to run the script
 */
public static String[] getRunScriptCommand(File script) {
 String absolutePath = script.getAbsolutePath();
 return WINDOWS ?
  new String[] {"cmd", "/c", absolutePath }
  : new String[] {"/bin/bash", bashQuote(absolutePath) };
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Returns a command to run the given script.  The script interpreter is
 * inferred by platform: cmd on Windows or bash otherwise.
 * 
 * @param script File script to run
 * @return String[] command to run the script
 */
public static String[] getRunScriptCommand(File script) {
 String absolutePath = script.getAbsolutePath();
 return WINDOWS ?
  new String[] {"cmd", "/c", absolutePath }
  : new String[] {"/bin/bash", bashQuote(absolutePath) };
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * Returns a command to run the given script.  The script interpreter is
 * inferred by platform: cmd on Windows or bash otherwise.
 *
 * @param script File script to run
 * @return String[] command to run the script
 */
public static String[] getRunScriptCommand(File script) {
 String absolutePath = script.getAbsolutePath();
 return WINDOWS ?
  new String[] {"cmd", "/c", absolutePath }
  : new String[] {"bash", bashQuote(absolutePath) };
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * A command to get a given user's group id list.
 * The command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 * This command does not support Windows and will only return group names.
 */
public static String[] getGroupsIDForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]{getWinUtilsPath(), "groups", "-F", "\"" + user +
             "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -g " + quotedUser + "; id -G " +
             quotedUser};
 }
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * A command to get a given user's groups list.
 * If the OS is not WINDOWS, the command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 */
public static String[] getGroupsForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]
    {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -gn " + quotedUser +
             "; id -Gn " + quotedUser};
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * a Unix command to get a given user's groups list.
 * If the OS is not WINDOWS, the command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 */
public static String[] getGroupsForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]
    {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -gn " + quotedUser +
             "; id -Gn " + quotedUser};
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * a Unix command to get a given user's groups list.
 * If the OS is not WINDOWS, the command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 */
public static String[] getGroupsForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]
    {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -gn " + quotedUser +
             "; id -Gn " + quotedUser};
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * a Unix command to get a given user's groups list.
 * If the OS is not WINDOWS, the command will get the user's primary group
 * first and finally get the groups list which includes the primary group.
 * i.e. the user's primary group will be included twice.
 */
public static String[] getGroupsForUserCommand(final String user) {
 //'groups username' command return is inconsistent across different unixes
 if (WINDOWS) {
  return new String[]
    {getWinUtilsPath(), "groups", "-F", "\"" + user + "\""};
 } else {
  String quotedUser = bashQuote(user);
  return new String[] {"bash", "-c", "id -gn " + quotedUser +
             "; id -Gn " + quotedUser};
 }
}

代码示例来源:origin: io.hops/hadoop-common

/** Return a command to send a signal to a given pid. */
public static String[] getSignalKillCommand(int code, String pid) {
 // Code == 0 means check alive
 if (Shell.WINDOWS) {
  if (0 == code) {
   return new String[] {Shell.getWinUtilsPath(), "task", "isAlive", pid };
  } else {
   return new String[] {Shell.getWinUtilsPath(), "task", "kill", pid };
  }
 }
 // Use the bash-builtin instead of the Unix kill command (usually
 // /bin/kill) as the bash-builtin supports "--" in all Hadoop supported
 // OSes.
 final String quotedPid = bashQuote(pid);
 if (isSetsidAvailable) {
  return new String[] { "bash", "-c", "kill -" + code + " -- -" +
    quotedPid };
 } else {
  return new String[] { "bash", "-c", "kill -" + code + " " +
    quotedPid };
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
 public void testBashQuote() {
  assertEquals("'foobar'", Shell.bashQuote("foobar"));
  assertEquals("'foo'\\''bar'", Shell.bashQuote("foo'bar"));
  assertEquals("''\\''foo'\\''bar'\\'''", Shell.bashQuote("'foo'bar'"));
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test
 public void testBashQuote() {
  assertEquals("'foobar'", Shell.bashQuote("foobar"));
  assertEquals("'foo'\\''bar'", Shell.bashQuote("foo'bar"));
  assertEquals("''\\''foo'\\''bar'\\'''", Shell.bashQuote("'foo'bar'"));
 }
}

相关文章