Gnome Editor--gedit building basic scripts

Source: Internet
Author: User
Tags echo command time and date

Gedit factorial.sh myprog.c

When you launch gedit with multiple files, it loads all the files into different buffers and displays each file in a tabbed window in the main editor window.

The key to Shell scripting is to enter multiple commands and process the results of each command, even if it is possible to pass the result of one command to another. The shell allows you to concatenate multiple commands in one step and use them.

such as: date;who

You can combine commands into a simple text file that you can simply run when you need to run these commands.

Create a shell script file

When you create a shell script file, you must specify the shell that you want to use in the first line of the file. Format:

#! /bin/bash

In the usual shell script line, the pound sign (#) is used as the comment line. Comment lines in shell scripts are not executed by the shell. Then, the first line of the shell script file is a special case, and the pound sign followed by an exclamation point tells the shell which Shell to use to run the script.

The contents of the script, if necessary, use a semicolon to enter the two commands you want to use on a single line. But in a shell script, you can list commands in different lines. The shell processes commands according to the order in which they appear in the file.

Execute script, appearing: Bash:test:command not found problem

Because the shell looks for the command through the PATH environment variable. Quick View PATH Environment variables:

Echo $PATH

The PATH environment variable is set to find commands only in a set of directories. To have the shell find the test script, you can:

(1) Add the directory where the shell script file is located to the PATH environment variable;

(2) The shell script file is referenced in the prompt with an absolute or relative file path.

Remember: To refer to a file in the current directory, you would use a single point operator in the shell:./test

When you execute the script again, such as the Bash:./test:permission denied appears

View file properties, Ls-l test

Modify file properties: chmod +777 Test

displaying messages

Sometimes you can add your own text message via the echo command to tell the user what the script is doing.

Echo This is a test

This is a test

Note: By default, you do not need to circle the text strings that will be displayed with quotation marks . But the quotation marks in the string may be troublesome:

Echo Let's see if this ' ll work

Lets see if THISLL work

The echo command can enclose a text string in single or double quotation marks. If you use them in a string, you need to enclose the string in one of the quotes in the text and the other.

echo "This was a test to see if you ' re paying attention"

This was a test to see if you ' re paying attention

If you want to display a text string on the same line as the command output. You can use the-n parameter of the Echo statement. Just change the first echo statement to:

Echo-n "The Time and date is:"

You can use these environment variables in your script by adding a dollar symbol ($) before the name of the environment variable

echo "USER info for userid: $USER"

Note that the environment variable in the echo command is replaced with the current value when the script is run.

$echo "The cost of the item is $"

The cost of the item is 5

Because the script will default to a variable. Show 5 again.

To display the dollar sign, you must add a backslash in front of him.

$echo "The cost of the item is \$15"

The cost of the item is $

${var}: Additional curly braces on both sides of the variable name are typically used to help identify the variable name of the dollar sign

Gnome Editor--gedit building basic scripts

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.