我通常会编写这样的 shell 脚本:
#!/bin/sh
nohup /path/to/myapp -test "$@" &
Run Code Online (Sandbox Code Playgroud)
然后,我可以从终端启动此 shell 脚本,并将我提供的任何命令行参数传递到 shell 脚本,然后将其传递到执行行 myapp。我使用的是 Ubuntu,问题出在 shell 脚本上,启动的图标不是 shell 文件的图标。它使用 myapp 的默认图标。这就是我转向 .desktop 的原因,它使启动的应用程序使用 .desktop 文件的图标。
我已经编写了一个 .desktop 文件:
[Desktop Entry]
Name=My Ro
Type=Application
Comment=Web Application
Exec=/path/to/myapp -test @
Icon=/opt/giteye/icon.xpm
Name[en_US]=My Ro
Run Code Online (Sandbox Code Playgroud)
我在执行行上放置了一个 @ 符号,但它没有按预期工作。它没有获取我提供给 .desktop 的命令行参数,也没有将其放入执行行中。您能帮我将 .desktop 收到的命令行参数传递给 Exec line/
我有一个如下所示的日志文件:
2015-07-07 11:23:33,006 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.LoggingInInterceptor@2798240a
name="New Test User"
domicile="A Place"
name="Test User"
2015-07-07 15:00:33,008 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.
Run Code Online (Sandbox Code Playgroud)
现在我用这样的参数调用我的 bash 脚本:
./test.sh -t 2015-07-07,11:00-2015-07-08,20:00.
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如果我使用像 2015-07-07 11:00 到 2015-07-08 20:00 这样的时间范围,如何获取日志文件中两个日期之间的文本?
谢谢
fish_vi_mode我最近通过添加到我的配置中启用了 Vi 模式。由于我这样做了Ctrl+F不再可以完成建议,因此我必须使用右箭头。
forward-char无论启用或未启用,键绑定都是相同的fish_vi_mode。根据fish_config,它们是:
forward-char Right Arrow
forward-char Right Arrow
forward-char CTRL - f
Run Code Online (Sandbox Code Playgroud)
Ctrl为什么+不能与启用F一起使用fish_vi_mode?
如何找到当前 Node.js 进程运行的用户 shell(bash等)?zsh
是否可以在不运行子进程的情况下找到它(例如,像这样)?
ps -p $$
Run Code Online (Sandbox Code Playgroud) 您可以使用${FUNCNAME[1]}(在 BASH 中,是否可以在函数体中获取函数名称?)来访问父函数名称。有没有办法也访问父函数参数长度(arity)?
所以代替这个:
get() {
[ "$#" != 2 ] && exit 1
}
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
get() {
assert_arity 2
}
assert_arity() {
local arity=${parent_function_arity}
local value=$1
[ "${arity}" != "${value}" ] && exit 1
}
Run Code Online (Sandbox Code Playgroud)
那可能吗?
我有两个文件,一行是一个字符串。我想在第一个文件中查找行,但不在第二个文件中查找行。不管顺序是什么(字符串存在的行号)。一个文件内没有重复的行。想知道 Linux 中的 shell 命令吗?
顺便说一句,如果有一种方法可以找到两个文件的共同行,那就太好了。:)
例如,
文件1,
hello
world
python
java
scala
Run Code Online (Sandbox Code Playgroud)
文件2,
hello
python
C++
C
Go
Run Code Online (Sandbox Code Playgroud)
我想输出,
world
java
scala
Run Code Online (Sandbox Code Playgroud)
提前致谢,林
这里遇到一些麻烦。我想将 ls 命令的输出捕获到变量中。然后稍后使用该变量并计算其中的行数。我尝试了一些变化
这是可行的,但如果没有 .txt 文件,它会说计数为 1:
testVar=`ls -1 *.txt`
count=`wc -l <<< $testVar`
echo '$count'
Run Code Online (Sandbox Code Playgroud)
这适用于没有 .txt 文件的情况,但当存在 .txt 文件时,计数会少 1:
testVar=`ls -1 *.txt`
count=`printf '$testVar' | wc -l`
echo '$count'
Run Code Online (Sandbox Code Playgroud)
此变体还表明,当不存在 .txt 文件时,计数为 1:
testVar=`ls -1 *.txt`
count=`echo '$testVar' | wc -l`
echo '$count'
Run Code Online (Sandbox Code Playgroud)
编辑:我应该提到这是 korn shell。
给出的内容test.txt如下:
Hello 10 love 20 haha 30
Hello Hello 11 love love 21 haha 31
41 Hello Hello 42 love love 43 haha 44
Run Code Online (Sandbox Code Playgroud)
我想要某种表达方式grep,以便在说完之后:
$ cat test.txt | grep ???
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
20
21
42
Run Code Online (Sandbox Code Playgroud)
如何实现这个功能呢?
使用java:
File file = new File("C:/Users/Administrator/Desktop/es.txt");
List<String> lines = FileUtils.readLines(file, "utf-8");
for (String line : lines) {
String[] arr = line.split("\\u007C\\u001C");
System.out.println(arr.length);
System.out.println(Arrays.toString(arr));
}
Run Code Online (Sandbox Code Playgroud)
我如何在 shell(awk、tr 或 sed)中执行此操作?我已经尝试过这个,但它不起作用:
awk -F\u007c\u001c '{print $1}' es.txt
Run Code Online (Sandbox Code Playgroud)
谢谢。
#! /bin/bash
if which gnupg >/dev/null; then
echo "Installed"
else
echo "Not installed" #If not installed
echo "Installing..."
sudo apt-get install gnupg #installation
fi
Run Code Online (Sandbox Code Playgroud)
你有什么主意吗?当我运行它时,它显示尚未安装,但它尝试更新它。结果它说:gnupg 已经是最新版本了。0 已升级,0 已新安装,0 已删除,46 未升级。