我有一个 csh 脚本,无论我做什么,它都不会回显正确的选项卡空间。
这就是我要的:
header 1 header 2 header 3 header 4
Run Code Online (Sandbox Code Playgroud)
情况1:
echo header 1 header 2 header 3 header 4 | tabify
Run Code Online (Sandbox Code Playgroud)
输出:它将替换所有空格到制表符
案例2:
echo "header 1\\theader 2\\theader 3\\theader 4"
Run Code Online (Sandbox Code Playgroud)
或者
echo header 1\\theader 2\\theader 3\\theader 4
Run Code Online (Sandbox Code Playgroud)
输出:标头 1\\标头 2\\标头 3\\标头 4
案例3:
echo -e "header 1\\theader 2\\theader 3\\theader 4"
Run Code Online (Sandbox Code Playgroud)
输出:-e header 1\\theader 2\\theader 3\\theader 4
帮助?TT
我正在一个网站上工作,并且在模板文件中使用具有开头和结尾的短代码。我想知道是否可以在短代码之间放置 wordpress the_content php 标签,以及是否可以在开始和结束标签之间放置另一个短代码。
我试过这个 -
<?php echo do_shortcode('[membership level="1"]''.$the_content.''[/membership]'); ?>
Run Code Online (Sandbox Code Playgroud)
但这不起作用,我也尝试了其他一些方法。我错过了什么或做错了什么?任何帮助深表感谢。谢谢。
我想打印一个数组而不打印方括号和“数组”这个词,例如,如果我这样做
print_r($Array);
Run Code Online (Sandbox Code Playgroud)
我会得到这个:
Array ( [0] => Example0 [1] => Example1)
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到这个?
Example0
Example1
Run Code Online (Sandbox Code Playgroud) 哪一种是在 Linux 中清理或清空文件的最佳方法?我必须将( tar )文件压缩到存档,然后清理/清空它;这就是我所做的并且它可以正常工作:
tar -zcvf /mnt/file.tar.gz /mnt/file.txt > /dev/null 2>&1
echo "" > /mnt/file.txt
Run Code Online (Sandbox Code Playgroud)
我正在用回声做这件事,可能有更好的方法吗?
谢谢
假设我正在使用 fgets 读取一个字符串,并且我想防止该字符串的字符在终端内部回显(没有 bash 技巧)。我怎样才能做到这一点?
我在变量中存储了很多文本。
text="This is sentence! this is not sentence! This is sentence. this is not sencence."
Run Code Online (Sandbox Code Playgroud)
我正在通过这个命令寻找句子:
echo $text | awk 'match($0,/([A-Z])([^!?.]*)([!?.])/) { print substr($0,RSTART,RLENGTH) }'
Run Code Online (Sandbox Code Playgroud)
我的输出是:
This is sentence!
Run Code Online (Sandbox Code Playgroud)
预期输出:
This is sentence!
This is sentence.
Run Code Online (Sandbox Code Playgroud)
更多示例: 文本中有语法正确和错误的句子。正确的句子由开头的大写字母和结尾字符 (.?!) 标识。我只想打印正确的句子。
text="incorrect sentence! this is not sentence! This is sentence. this is not sencence. This is correct sentence."
Run Code Online (Sandbox Code Playgroud)
预期输出:
This is sentence.
This is correct sentence.
Run Code Online (Sandbox Code Playgroud)
我能够找到第一个匹配项,但不是全部。感谢您的帮助 :)
我有一个变量,其中有一些行,我想用另一个变量中定义的许多换行符填充它。然而,子外壳似乎正在剥离尾随的换行符。我不能只使用 '\n' ,echo -e因为这些行可能已经包含需要按原样打印的转义字符。
我发现我可以使用它打印任意数量的换行符。
n=5
yes '' | sed -n "1,${n}p;${n}q"
Run Code Online (Sandbox Code Playgroud)
但是,如果我在子shell 中运行它以将其存储在变量中,则子shell 似乎会去除尾随的换行符。
我可以近似功能,但它很笨拙,并且由于我使用它的方式,我更愿意能够调用echo "$var"甚至将$var其自身用于诸如字符串连接之类的事情。一旦删除了变量的最后一行(填充符),这种近似就会遇到与子外壳相同的问题。
这是我的近似值
n=5
var="test"
#I could also just set n=6
cmd="1,$((n+1))p;$((n+1))q"
var="$var$(yes '' | sed -n $cmd; echo .)"
#Now I can use it with
echo "$var" | head -n -1
Run Code Online (Sandbox Code Playgroud)
本质上,我需要一种将许多换行符附加到变量的好方法,然后可以使用 echo 打印该变量。
如果可能的话,我想保持这个 POSIX 兼容,但在这个阶段,bash 解决方案也是可以接受的。我还将它用作工具的一部分,为此我设定了一个挑战,即在保持可读性的同时最小化行数和字符数。但是一旦我有了可行的解决方案,我就可以解决这个问题
这个程序叫做program.c. 当我运行时./program echo test,我希望程序打印test,即使命令是在子shell中运行的。为什么输出是空行?它与文件路径有关吗?当我尝试时,./program /bin/echo test我仍然得到一个空行输出。
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int function(char **argv) {
execl("/bin/bash", "sh", "-c", *argv, argv, (char*)NULL);
}
int main(int argc, char **argv) {
int return2;
function(argv + 1);
}
Run Code Online (Sandbox Code Playgroud) 以下命令行在 Windows 批处理文件中不起作用:
Powershell.exe -Command Get-Date -Format 'yyyy-MM-dd HH:mm:ss' echo "Hello World"
Run Code Online (Sandbox Code Playgroud)
预期结果为:2021-05-09 12:00:00 Hello World
但是 PowerShell 输出错误消息:
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "echo" to type "System.DateTime".
Error: "The string was not recognized as a valid DateTime. There is a unknown word starting at index 0."
At line:1 char:9
+ Get-Date <<<< -Format 'yyyy-MM-dd HH:mm:ss' echo Hello World
+ CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
Run Code Online (Sandbox Code Playgroud)
如何获取 PowerShell 命令的输出以获取格式的日期和时间yyyy-MM-dd HH:mm:ss …
例子:
testing="test"
var="\"${testing} the variable\""
testing="Update"
echo "$var"
Run Code Online (Sandbox Code Playgroud)
输出:测试变量
所需输出:更新变量