Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何重新排列shell脚本的输出_Bash - Fatal编程技术网

Bash 如何重新排列shell脚本的输出

Bash 如何重新排列shell脚本的输出,bash,Bash,给定以下shell脚本,如何重新排列输出以插入新行 #!/bin/bash echo -e $1 ` date ` 我试过-e开关,但没用 我的意思是,如果我键入:/script.sh“ls-la”我会得到以下输出: total 4732 drwxr-xr-x 4 root root 4096 2013-01-09 15:32 . drwx------ 28 root root 4096 2013-01-09 15:32 .. -rw-r--r-- 1 root root 484063 20

给定以下shell脚本,如何重新排列输出以插入新行

#!/bin/bash

echo -e $1 ` date `
我试过-e开关,但没用

我的意思是,如果我键入:
/script.sh“
ls-la
我会得到以下输出:

total 4732 drwxr-xr-x 4 root root 4096 2013-01-09 15:32 . drwx------ 28 root root 4096 2013-01-09 15:32 .. -rw-r--r-- 1 root root 484063 2013-01-06 05:22 Blackhat-europe-09-Damele-SQLInjection-whitepaper.pdf -rwxrwxrwx 1 root root 3787587 2013-01-06 05:10 FoxitReader-1.1.0.tar.bz2 -r-------- 1 root root 127693 2013-01-03 22:55 HackYeah-SQL-Injection.pdf drwxr-xr-x 2 root root 4096 2013-01-05 21:47 Inst_DVWA -rw-r--r-- 1 root root 3223 2012-12-22 00:47 nmap-O -rw-r--r-- 1 root root 284 2013-01-06 07:31 payload_dvwa.txt -rwxrwxrwx 1 root root 30 2013-01-09 11:18 script (copy).sh -rwxrwxrwx 1 root root 33 2013-01-09 15:32 script.sh -rw-r--r-- 1 root root 395493 2013-01-06 05:03 SQLmap_README.pdf -rwxrwxrwx 1 root root 705 2013-01-07 15:22 start_dvwa.sh -rw-r--r-- 1 root root 834 2013-01-06 07:31 Unsaved Document 1.txt drwxr-xr-x 2 root root 4096 2012-12-19 18:47 ZAP_certificate Wed Jan 9 15:32:55 CET 2013
我希望得到类似以下内容的输出:

total 4732
drwxr-xr-x  4 root root    4096 2013-01-09 15:32 .
drwx------ 28 root root    4096 2013-01-09 15:32 ..
-rw-r--r--  1 root root  484063 2013-01-06 05:22 Blackhat-europe-09-Damele-SQLInjection-whitepaper.pdf
-rwxrwxrwx  1 root root 3787587 2013-01-06 05:10 FoxitReader-1.1.0.tar.bz2
-r--------  1 root root  127693 2013-01-03 22:55 HackYeah-SQL-Injection.pdf
drwxr-xr-x  2 root root    4096 2013-01-05 21:47 Inst_DVWA
-rw-r--r--  1 root root    3223 2012-12-22 00:47 nmap-O 
-rw-r--r--  1 root root     284 2013-01-06 07:31 payload_dvwa.txt
-rwxrwxrwx  1 root root      30 2013-01-09 11:18 script (copy).sh
-rwxrwxrwx  1 root root      33 2013-01-09 15:32 script.sh
-rw-r--r--  1 root root  395493 2013-01-06 05:03 SQLmap_README.pdf
-rwxrwxrwx  1 root root     705 2013-01-07 15:22 start_dvwa.sh
-rw-r--r--  1 root root     834 2013-01-06 07:31 Unsaved Document 1.txt
drwxr-xr-x  2 root root    4096 2012-12-19 18:47 ZAP_certificate
非常感谢

试试看

echo -e "`$1`\n`date`"
#!/bin/bash
$*
date
引号应该保留换行符。

试试看

echo -e "`$1`\n`date`"
#!/bin/bash
$*
date
我不确定
/script“ls-la”
如何比
ls-la有所改进;日期
但我想你有你的理由


作为一个关键的可用性改进,我更喜欢不加引号的
/script ls-la
;只需切换
“$@”
,即可切换
$*
。然后,除其他事项外,将带引号的字符串作为参数传递也会起作用。例如,
/script perl-le'print 0x12,“foo”

示例输出中的
`date`
输出在哪里?您的
bash
脚本打算对作为您参数的
ls-la
执行什么处理?祝你好运。如果你的脚本看起来确实如此,那么
/script.sh“ls-la”
的输出将是
ls-la Wed Jan 9:52:22 EST 2013
。我不认为这是你想要的,但从你的问题很难确定。向我们展示(a)您的实际脚本,(b)它现在生成的输出,以及(c)您希望它生成的输出。并调整输出中的行数;你不需要这么多。你的尝试重复了一个常见的新手反模式:无用地使用Backticks。看见