Red Hat NETSCAPE MANAGEMENT SYSTEM 6.0 - COMMAND-LINE Manuel d'utilisateur Page 26

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 60
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 25
26
File Editing and Scripts
Vi - File Editor
vi filename
Press Insert key to type in inert mode
Press Escape key to leave insert and enter edit mode
To search, type /string and Enter
Search & replace on a line, type :s/oldpattern/newpattern/
Global search & replace, :%s/oldpattern/newpattern/g
Add a c at end of line if you want to confirm each change
:%s/oldpattern/newpattern/gc
:wq = write file (save) and quit
:q! = quit without saving
. = repeat last command
de = delete to end
dd = delete line
dw = delete word
u = undo last command (can be used multiple times)
yy = copy
cc = cut
p = paste
Batch file Linux uses scripts rather than batch files. There are three steps to creating a
script.
1. Design the script
2. Type it into a text file
3. Set the file’s attributes to tell Linux that it’s a script file (chmod a+x
filename)
Ok, so let’s walk through it. Here’s an extremely simple script that just
echoes back whatever you type in, called sayit:
echo $1
Change to your home directory. Use vi to create the script by typing vi
sayit. Then hit the Insert key and type echo $1. Press the ESC key. Now
type :x to save and exit. Type cat sayit to type out the file and verify it.
Finally, type chmod a+x sayit to make Linux see it as a script file.
Now type ./sayit “Hello World” and you should see Hello World echoed
back to the screen (we used quotes because there was a space, just like
Windows). Note that you have to type the whole path, even if you’re sitting
in the same directory.
Here’s another one, using a variable. Change the line echo $1 to echo Hello
$USERNAME. Then save and run it. Check it out! Linux has environment
variables similar to Windows. While Windows variables are surrouned by
% (i.e. %username$) Linux is simply preceded by a $.
echo to email echo “this is my text to email” | mail [email protected]
Vue de la page 25
1 2 ... 21 22 23 24 25 26 27 28 29 30 31 ... 59 60

Commentaires sur ces manuels

Pas de commentaire