shell

作者: jameiShi | 来源:发表于2018-11-16 11:18 被阅读3次

简介:

Shell 首先是 UNIX/Linux 下的脚本编程语言,它是解释执行的,无需提前编译。Shell 的语法细节和你熟悉的大部分编程语言都不太一样,需要重点学习。

Shell 同时也是一个程序,它的一端连接着 UNIX/Linux 内核,另一端连接着用户和其它应用程序;换句话说,Shell 是用户和应用程序与内核沟通的桥梁。


shell.png

shell 脚本:

解释型语言,执行时,需要使用解释器一行一行地转换为代码.如其它解释型语言:perl,python等.
第一个 shell 脚本:

#!/bin/bash
echo "Hello World !"

运行shell 脚本有两种方法:

1.作为可执行程序:
将上面的代码保存为 test.sh,并 cd 到相应目录:

chmod +x ./test.sh  #使脚本具有执行权限
./test.sh  #执行脚本

2.作为解释器参数:

/bin/sh test.sh

语法:

语法

应用

  • 自动打包:
#bin/bsah - l

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

cd /Users/suanle/ios_mmc
git pull
/usr/local/bin/pod install --verbose --no-repo-update

# 工程名
scheme_name="MMCApp"

# 文件名前缀
APP_NAME="买买车"

# info.plist路径
project_infoplist_path="${scheme_name}/Other/Info.plist"

#指定输出路径
export_path=/Library/WebServer/Documents/ota/MMCApp


#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
echo "========= $bundleShortVersion ========"

bundleShortVersion=$(($bundleShortVersion + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bundleShortVersion" "${project_infoplist_path}"
echo "========= $bundleShortVersion ========"

# 指定要打包编译的方式 : Release,Debug,AdHoc...
for build_configuration in Debug AdHoc Release
do
echo "**********build_configuration: $build_configuration"

# 指定输出ipa路径
export_ipa_path="${export_path}/${build_configuration}"
echo "*********输出的ipa路径: ${export_ipa_path}"
# 指定输出归档文件地址
export_archive_path="$export_path/${build_configuration}/$scheme_name.xcarchive"
echo "*********输出的归档文件路径: ${export_archive_path}"

# manifest.plist的文件路径
mainfestPlistPath="/Library/WebServer/Documents/ota/MMCApp/manifest/manifest_${build_configuration}_${bundleShortVersion}_mmc.plist"
echo "*********manifest.plist的文件路径:${mainfestPlistPath}"

cat << EOF > ${mainfestPlistPath}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>items</key>
    <array>
        <dict>
            <key>assets</key>
            <array>
                <dict>
                    <key>kind</key>
                    <string>software-package</string>
                    <key>url</key>
                    <string></string>
                </dict>
                <dict>
                    <key>kind</key>
                    <string>display-image</string>
                    <key>url</key>
                    <string></string>
                </dict>
                <dict>
                    <key>kind</key>
                    <string>full-size-image</string>
                    <key>url</key>
                    <string></string>
                </dict>
            </array>
            <key>metadata</key>
            <dict>
                <key>bundle-identifier</key>
                <string>com.ucarinc.mmcapp</string>
                <key>bundle-version</key>
                <string>2.0.0</string>
                <key>kind</key>
                <string>software</string>
                <key>title</key>
                <string>MMCApp</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>

EOF

#ipa下载地址
ipa_download_path="https://10.99.33.133/ota/$scheme_name/${build_configuration}"

# 导出ipa所需要的plist文件路径
if [ "$build_configuration" = "AdHoc" ] ; then
ExportOptionsPlistPath="$export_path/AdHocExportOptionsPlist.plist"
elif [ "$build_configuration" = "Release" ] ; then
ExportOptionsPlistPath="$export_path/AppStoreExportOptionsPlist.plist"
elif [ "$build_configuration" = "Debug" ] ; then
ExportOptionsPlistPath="$export_path/DevelopmentExportOptionsPlist.plist"
fi

# 指定输出ipa名称 : scheme_name + bundleShortVersion
DATE="$(date +%Y%m%d%H-%M-%S)"
ipa_name="${scheme_name}_V${bundleShortVersion}_${DATE}.ipa"

#下面2行是集成有Cocopods的用法
echo "=================clean================="
# xcodebuild -workspace "${scheme_name}.xcworkspace" -scheme "${scheme_name}"  -configuration ${build_configuration} clean

echo "+++++++++++++++++build+++++++++++++++++"

xcodebuild -workspace "${scheme_name}.xcworkspace" -scheme "${scheme_name}" -sdk iphoneos -configuration ${build_configuration} SYMROOT='$(PWD)'

xcodebuild clean -workspace ${scheme_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration}

xcodebuild archive -workspace ${scheme_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}

xcodebuild  -exportArchive \
-archivePath ${export_archive_path} \
-exportPath ${export_ipa_path} \
-exportOptionsPlist ${ExportOptionsPlistPath}

# 修改ipa文件名称
mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name

# 获取IPA下载链接
ipa_download_url=$(/usr/libexec/PlistBuddy -c "print items:0:assets:0:url" "${mainfestPlistPath}")

ipa_download_url=$"$ipa_download_path/$ipa_name"
echo "********ipa下载链接: $ipa_download_url ========"
# 更改 plist 文件中的下载地址
/usr/libexec/PlistBuddy -c "Set :items:0:assets:0:url $ipa_download_url" "${mainfestPlistPath}"

done
  • 其它
    pods 库:(在编译阶段会执行一些脚本)
checkpodsmanifest.lock.png

相关文章

  • Shell 学习

    shell 变量 shell 参数传递 shell 数组 shell 运算符 shell echo 命令 prin...

  • Shell 概述

    学习 Shell 主要包括的内容: Shell 脚本入门 Shell 变量 Shell 内置命令 Shell 运算...

  • Shell 教程

    Shell 变量 Shell 传递参数 Shell 数组 Shell 基本运算符 Shell echo 命令 Sh...

  • shell 第一天

    shell编程初识 1.1 shell编程初识 shell的定义 Shell 是命令解释器 Shell 也是...

  • shell 案例

    Shell编程一 Shell防范ARP攻击 Shell编程二 Shell防范DDos攻击 Shell编程三 ...

  • 【生物信息笔记】shell 脚本 (dry-2)

    shell 和 shell script(脚本)区别: shell 和 shell 脚本是两个不同概念,shell...

  • Linux Shell:基础知识和Shell变量

    摘要:Linux,Shell 整理Shell内容要点: Shell基础知识 Shell变量的类型 Shell变量赋...

  • Shell脚本语言一

    一、语法 格式 运行 Shell变量 Shell字符串 Shell数组 Shell注释 Shell传递参数 She...

  • 使用shell脚本

    使用方式 shell 变量 shell 字符串操作 shell 数组 shell 注释 shell 命令行参数 s...

  • vim学习 09——shell命令

    vim学习 09——shell命令 执行 shell 命令 :!shell命令 : 可以执行 shell 命令。 ...

网友评论

      本文标题:shell

      本文链接:https://www.haomeiwen.com/subject/lgpkfqtx.html