小编ram*_*rur的帖子

一个像其他语言一样接受参数的 bash 函数?

我有一个 bash 函数来设置$PATH这样的——

assign-path()
{
    str=$1
    # if the $PATH is empty, assign it directly.
    if [ -z $PATH ]; then
        PATH=$str;
    # if the $PATH does not contain the substring, append it with ':'.
    elif [[ $PATH != *$str* ]]; then
        PATH=$PATH:$str;
    fi
}
Run Code Online (Sandbox Code Playgroud)

但问题是,我必须为不同的变量编写不同的函数(例如,为$CLASSPATHlikeassign-classpath()等编写另一个函数)。我找不到将参数传递给 bash 函数的方法,以便我可以通过引用访问它。

如果我有类似的东西会更好 -

assign( bigstr, substr )
{
    if [ -z bigstr ]; then
        bigstr=substr;
    elif [[ bigstr != *str* ]]; then
        bigstr=bigstr:substr;
    fi
}
Run Code Online (Sandbox Code Playgroud)

任何想法,如何在 bash …

bash bash-script

17
推荐指数
2
解决办法
3万
查看次数

java插件在chrome浏览器中不起作用(所有可能的尝试都用尽了)

我在 Ubuntu 12.04 机器上使用谷歌浏览器,最近我需要切换到铬浏览器。我正在使用 Ubuntu 软件中心提供的版本。问题是我不能再让java小程序加载了。

这是我的情况——

  1. 我正在使用oracle 中的vanilla jdk ( jdk 1.7.0_51 )。
  2. 以前在 chrome 中,我创建了一个libnpjp2.so指向/opt/google/chrome/plugins文件夹的符号链接,java 小程序工作正常。
  3. 卸载Chrome并安装铬浏览器后,我做了一个符号链接libnpjp2.so/usr/lib/chromium-browser/plugins文件夹,但Java小程序没有火起来的话(甚至从这个网站http://www.java.com/en/download/installed.jsp
  4. 甚至libnpjp2.so出现在about:plugins铬浏览器中并显示它已启用。

到目前为止我尝试过的-

  1. 卸载chrome后,它/opt/google/chrome仍然存在,我删除了它
  2. 将符号链接作为上面的第 3 点到/usr/lib/chromium-browser/plugins,但没有运气。
  3. 所以我icedtea-7-plugins从 Ubuntu 存储库安装并创建了一个符号链接IcedTeaPlugin.soto /usr/lib/chromium-browser/plugins,但没有运气,所以我删除了它。
  4. 在java控制面板的排除列表中添加了java小程序测试页面。
  5. 从 Java 控制面板清除临时 Internet 文件。
  6. 在chrome浏览器中多次循环“启用/禁用”java插件。
  7. -enable-plugins开关启动铬浏览器不起作用。

当我进入java小程序测试页面时,我只能看到一个灰色的矩形,没有别的。请注意,在 chrome 浏览器和 Firefox 中一切正常。另请注意,我不想安装 openjdk 的东西。

任何的想法 ?

ubuntu chrome java plugin

6
推荐指数
1
解决办法
3万
查看次数

当我在一个符号链接的文件夹中时,从父位置复制文件

假设我在/tmpcalledparent和 中创建了两个文件夹childchild包含一个名为的文件test-child.txtparent包含一个名为test-parent.txt. 现在让我们进入parent并创建一个符号链接到child. 接下来,进入child并尝试test-parent.txtparent. bash 完成工作,但实际的文件复制失败——

cd /tmp
pwd
/tmp
mkdir parent
mkdir child
touch child/test-child.txt
ls child/
test-child.txt
cd parent
ln -sf ../child .
touch test-parent.txt
cd child
cp ../test-parent.txt .
cp: cannot stat ‘../test-parent.txt’: No such file or directory 
Run Code Online (Sandbox Code Playgroud)

为什么 ??

此外,当我在里面时child,如果我说——

pwd
/tmp/parent/child
Run Code Online (Sandbox Code Playgroud)

cp symlink directory-structure pwd

2
推荐指数
1
解决办法
424
查看次数

标签 统计

bash ×1

bash-script ×1

chrome ×1

cp ×1

directory-structure ×1

java ×1

plugin ×1

pwd ×1

symlink ×1

ubuntu ×1