bash - 从第二个函数参数开始的 Ruby for 循环
问题描述
如何从第二个参数开始迭代我的函数参数?
#!/bin/bash -
function test23() {
echo 'hello world'
for text in $2..$@
do
echo $text
done
}
test23 start with the second argument
我目前的输出是
hello world
with..start
with
the
second
argument
我想得到“第二个论点”。
解决方案
你可以shift
:
#!/usr/bin/env bash
test23() {
echo 'hello world'
shift
for text
do
printf '%s\n' "$text"
done
}
推荐阅读
- python - 有没有办法在 python 中放大绘图的某个部分以减少“空白空间”
- html - 如何通过href值单击html标签,puppeteer?
- gtk - 在 gtkmm3 中使用 Gtk::Assistant
- flask - 如何在烧瓶应用程序中默认获取我的 localhost url?
- vue.js - 无法在 Axios 调用之外返回 Promise 值
- java - 为开发目的模拟 Spring Bean
- r - 用于在 igraph/R 中绘制网络的默认算法是什么?
- reactjs - ReactNative-Expo:使用全新应用程序丢帧
- google-sheets - 是否可以在日历视图中显示单个记录的多个条目?
- python - 时间戳分析 Pandas