给定以下shell脚本,如何重新排列输出以插入新行?如何重新排列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
非常感谢
其中是您的示例输出中'\'date \''的输出?你的'bash'脚本是用来处理'ls -la'的,这是你的论点?祝你好运。 – shellter
如果你的脚本看起来像这样,'./script.sh“ls -la”'的输出将是'ls -la Wed Jan 9 09:52:22 EST 2013'。我不认为这就是你想要的,但很难从你的问题确定。向我们展示(a)您的实际脚本,(b)它现在产生的输出,以及(c)您希望它产生的输出。并修剪输出中的行数;你不需要那么多。 – larsks
您的尝试重复一个常见的新手反模式:无用的反引号。请参阅http://partmaps.org/era/unix/award.html#backticks – tripleee