Shell BASICS (1) starting from hello world, shell Basics
Note: Here are the shell notes I made. Next, we will provide a series of notes.
Shell is a scripting language, so there must be an interpreter to execute these scripts. Common Shell script interpreters in Unix/Linux include bash, sh, csh, and ksh. They are used to being called a Shell. We often talk about the number of Shell types. In fact, it refers to the Shell script interpreter.
As for the introduction and differences between these script interpreters, I am not clear about them. I should check the information myself. In fact, it is not very important to know whether or not I know it. This does not affect whether you can use shell.
1. Create a new file, such as lottu01.sh, with the extension sh (sh stands for shell). The extension does not affect script execution. Let's start with "hello world.
#!/bin/bashecho "hello world !"
Note: "#!" Is an agreed tag, which tells the system what interpreter is required to execute this script, that is, which Shell is used. Use bash.
Echo: Is the output command in shell, and outputs the string following it to the screen. -- This is also known to all.
2. Run the script
$ Chmod + x lottu01.sh # grant the script execution permission $./lottu01.shhello world!
Note that you must write it as./test. sh instead of test. sh.
Write test directly. sh, the linux system will go to the PATH to find whether it is named test. sh, and only $ HOME/bin, $ HOME/sbin,/usr/bin,/usr/sbin and so on are in the PATH. Your current directory is usually not in the PATH, therefore, it is written as test. sh cannot find the command. /test. sh tells the system to find it in the current directory.
Of course, you can also write test. sh. Perform the following operations:
Cp lottu01.sh ../bin/# ../bin is under the bin of the home directory of the current user. Don't misunderstand this.
Then test whether lottu01.sh is OK.
$cp lottu01.sh ../bin/$ lottu01.sh hello world !
3. read command
Echo is the output in shell, So input. read. -- This will be explained in detail in later sections -- read.
#! /Bin/bash # Author: lottu # Copyright (c) li0924 # start scriptecho "please input your name? "Read nameecho" HI, $ {name} "test: $ chmod + x lottu02.sh $./lottu02.sh please input your name? Lottu -- name you entered here. HI, lottu
[Note]
1. The first line of the script -#! /Bin/bash; it is the interpreter of the script. Of course, you can leave it empty. At that time, you must execute it like this.
/Bin/bash script;
2. echo, read command; this will be added later.
In linux, how can I write a C ++ file that outputs hello world using the shell script language to execute this C ++ file?
Save the source file as hello. cpp and start compilation.
$ G ++-o hello. cpp
After the compilation is complete, generate a file named hello in the current path, and then execute
$./Hello
On the screen, you will see the printed result: Hello, Linux.
Note: by default, after compilation is successful, a file named a is generated in the current path. and then execute $. /. the output can be printed, but the name of the executable program can be specified by option-o;
2. Compile multiple source files
3. Use the external function library
4. Use the shared function library and static function library
5. Detailed description of gcc options
Mac OS shell script hello world
1) You can use shell
Create a new a. sh with the following content:
#! /Bin/bash
Echo 'Hello world'
Save and run the following command:
Chmod + x a. sh
./A. sh
2) If it is deployed on a mac, you can use aumator, which has many advanced features and can wrap the script into an application. If it is on Mac, it is recommended to use ActionScript.