About Linux shell programming, alias Rm= ' CP $@ ~/backup; RM $@ '

Source: Internet
Author: User

This example of the book needs to be supported in Ubuntu's lower version of the system, and now basically does not support, want to implement it is very simple to write a script to back up and then delete.

Alias has just made a replacement.
Alias rm= ' CP [email protected] ~/backup; RM [email protected] '
RM text.txt
was converted into a
CP [email protected] ~/backup; RM [email protected] text.txt that
CP ~/backup; RM text.txt
You can see that text.txt has been removed.

This does not work, and the first statement cannot get the arguments. I don't know why I can't do this. But I can give you an alternative, which is to define a function that takes arguments as arguments to the function:

Alias saferm= ' Saferm () {CP [email protected] ~/backup; RM [email protected];}; saferm [email protected] ' saferm abc.txt

So you can write as many commands as you like.

However, if the command is complicated, it is recommended to write the shell script

#!/bin/bash

#/home/yourname/saferm

CP [email protected] ~/backup RM [email protected]

Then create an alias

chmod +x/home/yourname/saferm

Alias Saferm=/home/yourname/saferm

can also be placed directly under the system path ~

About Linux shell programming, alias Rm= ' CP [email protected] ~/backup; RM [email protected]'

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.