shell rev

在linux系統上查看rev的做用php

NAME
     rev — reverse lines of a file or files

SYNOPSIS
     rev [-V] [-h] [file ...]

DESCRIPTION
     The rev utility copies the specified files to standard output, reversing
     the order of characters in every line.  If no files are specified, stan‐
     dard input is read.

     -V, --version
             Output version information and exit.

     -h, --help
             Output help and exit.

上面已經說明得很清楚,其做用是反序一個文件或者多個文件的每一行。若是存在識別不是文件的狀況,它就是從標準輸入流中讀取。先看兩個文件的開頭內容linux

test.sh的文件內容shell

lhj@lhj-virtual-machine:~$ cat test.sh 
#!/bin/bash
a=$(pwd)
echo ${a}

test.php的文件開頭的內容bash

lhj@lhj-virtual-machine:~$ head test.php 
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| File and Directory Modes
|--------------------------------------------------------------------------
|
| These prefs are used when checking and setting modes when working
| with the file system.  The defaults are fine on servers with proper
| security, but you may wish (or even need) to change the values in

 使用rev反序單個文件dom

lhj@lhj-virtual-machine:~$ rev test.sh
hsab/nib/!#
)dwp($=a
}a{$ ohce

    使用rev反序多個文件lua

lhj@lhj-virtual-machine:~$ rev test.sh test.php 
hsab/nib/!#
)dwp($=a
}a{$ ohce
;)'dewolla ssecca tpircs tcerid oN'(tixe ))'HTAPESAB'(denifed ! ( fi  php?<

*/
--------------------------------------------------------------------------|
sedoM yrotceriD dna eliF |
--------------------------------------------------------------------------|
|
gnikrow nehw sedom gnittes dna gnikcehc nehw desu era sferp esehT |
reporp htiw srevres no enif era stluafed ehT  .metsys elif eht htiw |
ni seulav eht egnahc ot )deen neve ro( hsiw yam uoy tub ,ytiruces |
hcae rof ssecorp etarapes a gninnur ehcapA( stnemnorivne niatrec |
dluohs seulav latcO  .).cte ,CEXEus ehcapA htiw IGC rednu PHP ,resu |
.yltcerroc edom eht tes ot desu eb syawla |

    反序不是文件的code

lhj@lhj-virtual-machine:~$ echo $a
1 2 3 4 5
lhj@lhj-virtual-machine:~$ echo ${a}|rev
5 4 3 2 1