Shell Script Learning 1 (Linux script Raiders)

Source: Internet
Author: User

sudo <command> < arguments> equivalent to root permission execution command

Give executable permissions to all user files: chmod a+x script.sh

Execute script:
./script.sh#./represents the current directory

Command 1:echo "Welcome to Bash"

Command 2:printf "Hello World"

Difference: printf does not carry a newline!

Example1:

#!/bin/bash

printf "%-5s%-10s%-4s\n" No Name Mark

Command 3: View environment variables when the process is running:

cat/proc/$PID/environ (PID is the ID of the process)

Command 4: Get the ID of the process

Pgrep gedit

12501 (ID of the gedit process)

You can view the environment variables for a process by using the following command:

Cat/proc/12501/environ/gdm_keyboard_layout=usgnome_keyping=1560user=slynuxhome=/home/slynux

Change command to return a list containing environment variables and corresponding variable values

Command 5:tr ' \ n ' to replace command

Attention:

Var=value is an assignment operation, var = value is an equal operation, error prone;

Example:

Var= "Value"

echo $var (output content, using $ symbol)

The latter echo ${var}

Environment variables are variables that are not defined in the current process and are inherited from the parent process;

To add a new path in path:

Export path= "$PATH:/home/user/bin"

You can also use:
Path= "$PATH:/home/user/bin"

Export PATH

Shell Script Learning 1 (Linux script Raiders)

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.