换壳程序-这是什么? [英] Shell shift procedure - What is this?

查看:197
本文介绍了换壳程序-这是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在shell中,我们有命令shift,但是我在一些示例中看到了它的移位3

In shell we have the command shift, but i saw on some example its giving shift 3

为什么上班后会有一个数字?那是什么呢?它是做什么的?

Why there is a number after shift ? and what its about ? what it does ?

示例:

echo "arg1= $1  arg2=$2 arg3=$3"
shift
echo "arg1= $1  arg2=$2 arg3=$3"
shift   
echo "arg1= $1  arg2=$2 arg3=$3"
shift  
echo "arg1= $1  arg2=$2 arg3=$3"
shift

输出将是:

arg1= 1 arg2=2  arg3=3 
arg1= 2 arg2=3  arg3= 
arg1= 3 arg2=   arg3=
arg1=   arg2=   arg3=

但是当我添加它时,它无法正确显示它.

But when i add that, it doesn't display it correctly.

推荐答案

看看 man 页面,其中说:

shift [n]
    The  positional parameters from n+1 ... are renamed to $1 .... 
    If n is not given, it is assumed to be 1.

示例脚本:

#!/bin/bash
echo "Input: $@"
shift 3
echo "After shift: $@"

运行它:

$ myscript.sh one two three four five six

Input: one two three four five six
After shift: four five six

这表明在移位3后,分别是$1=four$2=five$3=six.

This shows that after shifting by 3, $1=four, $2=five and $3=six.

这篇关于换壳程序-这是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆