我有一个 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 …
我在 Ubuntu 12.04 机器上使用谷歌浏览器,最近我需要切换到铬浏览器。我正在使用 Ubuntu 软件中心提供的版本。问题是我不能再让java小程序加载了。
这是我的情况——
libnpjp2.so指向/opt/google/chrome/plugins文件夹的符号链接,java 小程序工作正常。libnpjp2.so到/usr/lib/chromium-browser/plugins文件夹,但Java小程序没有火起来的话(甚至从这个网站http://www.java.com/en/download/installed.jsp)libnpjp2.so出现在about:plugins铬浏览器中并显示它已启用。到目前为止我尝试过的-
/opt/google/chrome仍然存在,我删除了它/usr/lib/chromium-browser/plugins,但没有运气。icedtea-7-plugins从 Ubuntu 存储库安装并创建了一个符号链接IcedTeaPlugin.soto /usr/lib/chromium-browser/plugins,但没有运气,所以我删除了它。-enable-plugins开关启动铬浏览器不起作用。当我进入java小程序测试页面时,我只能看到一个灰色的矩形,没有别的。请注意,在 chrome 浏览器和 Firefox 中一切正常。另请注意,我不想安装 openjdk 的东西。
任何的想法 ?
假设我在/tmpcalledparent和 中创建了两个文件夹child。child包含一个名为的文件test-child.txt并parent包含一个名为test-parent.txt. 现在让我们进入parent并创建一个符号链接到child. 接下来,进入child并尝试test-parent.txt从parent. 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)