我希望输出为$ msg1两三.$和msg1之间没有空格.怎么可能?
#!/bin/sh
msg1=$
ms="$msg1 msg1"
msg2="$ms two"
msg3="$msg2 three"
echo $msg3
Run Code Online (Sandbox Code Playgroud) 我正在搞乱我的.bash_profile文件(Mac OSX),当我尝试设置别名时:
别名.=".〜/ .bash_profile"
我随后无法获取我的.bash_profile文件(退出文件后键入"source .bash_profile"并停留在非终止进程中).当我将别名更改为:
别名s =".〜/ .bash_profile"
一切都很好.这是怎么回事?
我有一个包含以下格式的数据的文件:
{"parameter":"toto.tata.titi", "value":"0/2", "notif":"1"}
Run Code Online (Sandbox Code Playgroud)
我使用sed对文件进行了更改:
sed -i "/\<$param\>/s/.*/$line/" myfile
Run Code Online (Sandbox Code Playgroud)
哪个line变量是
{"parameter":"toto.tata.titi", "value":"0/2", "notif":"3"}
Run Code Online (Sandbox Code Playgroud)
和param变量是toto.tata.titi
以上sed命令返回错误:
sed: unmatched '/'
Run Code Online (Sandbox Code Playgroud)
因为line变量包含/==>"0/2"
即使line变量包含,如何更新我的sed命令使其工作/?
我正在尝试对awk输出过程进行一些人为操作。我的示例文件包含字符串,它是计数。现在,我正在尝试将计数值设置为MB格式(默认计数将以字节为单位。)
示例:myfile.txt
a 123455
b 34455566
c 10394934839
d 102445555
Run Code Online (Sandbox Code Playgroud)
我的脚本:
cat myfile.txt | while read line; do name=$line ; name=`echo $fname|awk '{print $1}'` ; cnt=`echo $fname|awk '{print $1}'`; if [$cnt -gt 1024] ; then echo "$name value in critical $cnt";fi done
Run Code Online (Sandbox Code Playgroud)
问题:我希望将cnt值转换为MB(cnt / 1024/1024)。
不知道如何实现这一目标。
我编写了一个小*nix实用程序,每次检测到文件系统更改时都会'重新运行'给定的命令.所以我将命令作为引用参数运行,例如
rerun "my command"
Run Code Online (Sandbox Code Playgroud)
重新运行是用Python编写的,最后调用:
subprocess.call("my command", shell=True, executable=USERS_DEFAULT_SHELL)
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我的默认shell是'/ bin/bash'.但是,subprocess.call调用的shell不是"交互式"shell,因此无法识别我的.bashrc中定义的shell函数和别名.
man bash告诉我,为了启动交互式shell,我将'-i'传递给/ bin/bash.但是,可以预见,
subprocess.call(..., executable='/bin/bash -i')
Run Code Online (Sandbox Code Playgroud)
不起作用 - 它无法找到该名称的可执行文件.(即使它确实有效,我也试图为用户默认的shell设置此功能,而不仅仅是Bash.可能'-i'对所有其他shell都没有做同样的事情.)
我怎样才能从Python中执行"我的命令",就像用户在终端中键入它时所解释的一样?
以下脚本:
IP=`ifconfig en0 inet | grep inet | sed 's/.*inet *//; s/ .*//'`
Run Code Online (Sandbox Code Playgroud)
从ipconfig命令中隔离IP地址并将其放入变量中$IP.我现在如何从上述IP地址中隔离最后一个八位字节并将其放入第二个变量中 - $CN
例如:
$ IP = 129.66.128.72 $ CN = 72或$ IP = 129.66.128.133 $ CN = 133 ...
我正在尝试查找用于在Red Hat Enterprise Linux Server 6.5中显示已安装内存(RAM)的命令。
我发现以下命令:
cat /proc/meminfo | grep MemTotal
Run Code Online (Sandbox Code Playgroud)
但是看起来MemTotal值不是实际的RAM值。我想知道系统的实际RAM(类似于Windows中的Installed memory(RAM))。
谢谢你的帮助。
嗨,我有一个Unix Shell脚本调用Food.sh; 我有一个Perl脚本调用Track.pl.有没有办法我可以将Track.pl的代码放入Food.sh代码并仍然有效?Track.pl需要一个arugement来标记文件夹的名称.
基本上它会像这样运行.
Unix Shell Script codes RUN
step into
Perl Script codes RUN
Put in name of folder for Perl script
Rest of script runs
exit out.
Run Code Online (Sandbox Code Playgroud) 我想从网页导出Skype ID,数据如下:
contact skype:youarefriend"
Run Code Online (Sandbox Code Playgroud)
我只想导出youarefriend我的结果.我可以用:
grep -oP 'skype:.*?"'
Run Code Online (Sandbox Code Playgroud)
但结果是skype:youarefriend".我可以获得没有skype:前缀的输出吗?
shell ×10
bash ×5
linux ×4
awk ×2
sed ×2
batch-file ×1
grep ×1
ip-address ×1
perl ×1
python ×1
redhat ×1
regex ×1
subprocess ×1
terminal ×1
unix ×1