linux - Shell 脚本,命令行参数

标签 linux shell

任务是写一个shell脚本 输入是一个字符串和一个数字

例如,

xxx.sh“ Hello World ”3

输入将是

***************
* Hello World *
* Hello World *
* Hello World *
***************

这是我到目前为止得到的:

function mantra()   {
    echo "string is $1"
    echo "number is $2"

    echo $string
    echo $PATH
    for num in string_length; do
        echo "*"
    done
}

如何计算字符串中的字符数? 我做得对吗?我不确定如何将命令行参数传递到我的函数中。Blockquote

最佳答案

您输入的字符串中的字符数是${#1}

参见 this一个简短的解释页面。

关于linux - Shell 脚本,命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4135657/

相关文章:

linux - CentOS 从 CSV 文件脚本创建用户

linux - 使用 crontab 运行带参数的脚本

linux - 如何创建 cron 命令

linux - 使用相同的 id_rsa 和 id_rsa.pub 在多个用户帐户上使用 ssh 登录

linux - 带有 "["和 "]"分隔符的 awk 错误

shell - 在 unix 中向文件中的任意位置添加一列 [使用 awk 或 sed]

linux - Live Linux grep 脚本 - 只打印肯定的结果

linux - 无法使用 ant exec 任务运行 bash 脚本

linux - 有没有办法通过 shell 脚本上的 SFTP 下载与模式匹配的文件?

java - 使用 build.sh 脚本构建 Android