我有办法简化这些回声吗? [英] Is there a way for me to simplify these echos?

查看:53
本文介绍了我有办法简化这些回声吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在学习如何shell脚本,并且面临着使我更容易回显"Name1""Name2" ..."Name15"的挑战,而且我不太确定从哪里开始.我有主意,但是如果我搞砸了,我不想显得傻.有帮助吗?

I am still learning how to shell script and I have been given a challenge to make it easier for me to echo "Name1" "Name2"..."Name15" and I'm not too sure where to start, I've had ideas but I don't want to look silly if I mess it up. Any help?

我实际上还没有尝试过任何东西,但大多数人都只是想过.

I haven't actually tried anything just yet it's all just been mostly thought.

#This is what I wrote to start 

#!/bin/bash

echo "Name1"
echo "Name2"
echo "Name3"
echo "Name4"
echo "Name5"
echo "Name6"
echo "Name7"
echo "Name8"
echo "Name9"
echo "Name10"
echo "Name11"
echo "Name12"
echo "Name13"
echo "Name14"
echo "Name15"

我的预期结果显然只是为了输出"Name1","Name2"等.但是我正在寻找一种更具创造性的方法.如果可能的话,可以通过几种方式来做到这一点,以便我学习.谢谢.

My expected results are obviously just for it to output "Name1" "Name2" etc. But I'm looking for a more creative way to do it. If possible throw in a few ways to do it so I can learn. Thank you.

推荐答案

最简单(可能不是最具创造力)的方法是使用printf:

The easiest (possibly not the most creative) way to do this is to use printf:

printf "%s\n" name{1..15}

这取决于bash大括号扩展{1..15}具有15个字符串.

This relies on bash brace expansion {1..15} to have the 15 strings.

这篇关于我有办法简化这些回声吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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