Basic knowledge about Linux: a simple shell

Source: Internet
Author: User
Article title: basic knowledge of Linux: simple shell writing. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Script
  
To create a shell script, you can start by editing an existing shell script. For example, pico writes a script that uses common options to run the tar command to unbind files downloaded from the Internet.
  
$ Pico untar
  
Because untar is not saved in the current path, it is created. Then, enter the following content:
  
#! /Bin/bash
  
Echo this is the script file $0
  
Echo untarring the file $1
  
# Calltar with options-zxvf (filter through gzip, extract, verbose, filename)
  
Tar-zxvf $1
  
You can use Key to save, use Key to exit pico.
  
The first line of the script indicates what shell is used to execute the script. it must start with "#", otherwise it will not be executed. Other rows starting with "#" are comments and won't be executed by shell.
  
$0, $1, $2... is the parameter passed to the shell script. assume that when you execute the script, the parameters a, B, and c. g are used:
  
$ Script a B c d e f g
  
$0 indicates "script", $1 indicates "a", $2 indicates "B", and $3 indicates "c.
  
The echo function is to echo any information behind it on the screen.
  
Now, set the file to executable.
  
$ Chmod u + x untar
  
This script can be used now. Use the following command to open the my_tar.tar.gz file.
  
$./Untar my_tar.tar.gz
  
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.