Bash 如何将两个脚本合并为一个脚本

Bash 如何将两个脚本合并为一个脚本,bash,file,scripting,Bash,File,Scripting,我正在寻找将这两个脚本合并为一个脚本的方法: 我使用第一个脚本将文件放入目录中。 我可以将其修改为写入其他文件夹。 但我必须只用一个。我如何才能做到这一点?如前所述,只需查看文件的不同之处,并在这些行中替换起类似作用的部分即可。在这种情况下,您可以使用单个变量来完成。如果使用{} 在这种情况下,您可以运行脚本并向其传递所需的子路径: /myscript.sh../Napster.app/it.lproj 或 /myscript.sh../Napster.app 如果不带参数运行它,它将用作默

我正在寻找将这两个脚本合并为一个脚本的方法:


我使用第一个脚本将文件放入目录中。
我可以将其修改为写入其他文件夹。

但我必须只用一个。我如何才能做到这一点?

如前所述,只需查看文件的不同之处,并在这些行中替换起类似作用的部分即可。在这种情况下,您可以使用单个变量来完成。如果使用
{}

在这种情况下,您可以运行脚本并向其传递所需的子路径:

/myscript.sh../Napster.app/it.lproj


/myscript.sh../Napster.app

如果不带参数运行它,它将用作默认值
。/Napster.app/it.lproj

#!/bin/sh
MyPath=${1:-../Napster.app/it.lproj"}

if [ -f "/var/mobile/temp.temp" ];then
rm "/var/mobile/temp.temp"
fi

ls -d /var/mobile/Applications/*/*.app | sort -f -t \/ -k 6 | while read OneApp
do
        AppName=$(echo $OneApp | cut -f 6 -d '/')
        cd "$OneApp";
devicebundleid=$(plutil -key CFBundleIdentifier Info.plist)
if [ "$devicebundleid" = "com.rhapsody.iphone.Napster3" ]; then
        pwd >/var/mobile/temp.temp
fi
done
if [ ! -f "/var/mobile/temp.temp" ];then
        echo "Napster not found. if your sure its install please report to the repo manager"
else
        dir=$(cat "/var/mobile/temp.temp")
        backup="$dir/../backup.tar.gz"
        gamefiles=/files.tmp
        hackedfiles=/hackedfiles.tmp
        matchingfiles=/matchingfiles.tmp
        itunesmeta=$dir/../iTunesMetadata.plist
        info=$dir/Info.plist
        binname=$(plutil -key CFBundleExecutable $dir/Info.plist)


        if [ -f $dir/../iTunesMetadata.plist ];then
                if grep -q "bundleShortVersionString" "$itunesmeta"
                then myappver=$(plutil -key bundleShortVersionString $itunesmeta)
                else myappver=$(plutil -key bundleVersion $itunesmeta)
                fi
        else
                plutil -xml $info  2>&1>/dev/null
                if grep -q "CFBundleShortVersionString" "$info"
                then myappver=$(plutil -key CFBundleShortVersionString $info)
                else myappver=$(plutil -key CFBundleVersion $info)
                fi
        fi

        echo "###########"
        echo "# Description #"
        echo "###########"
        echo "XX SUPERGIU XX"
        sleep 1
        echo

        echo "######"
        echo "# Log #"
        echo "######"

        echo -n " -Checking Files..."
        if [ ! -d "/hack" ]; then
                echo
                echo " *** Error ***"
                echo
                echo "***********************************************"
                echo "   *No files found in /hack***"
                echo "   *Please report this to the repo manager"
                echo
                echo "***********************************************"
                echo
                exit 0
        else
                sleep 1
                echo " Success"
        fi

        echo -n " -Finding Napster..."
        sleep 1
        echo " Success"

        echo -n " -Locating Matching Files..."
        sleep .1
        echo " Success"

        echo -n " -Making Backup..."    
        ls $dir/${MyPath}/ >$gamefiles
        ls "/hack" >$hackedfiles
        grep -i -E -f $gamefiles $hackedfiles >$matchingfiles

        for line in `cat $matchingfiles`
        do tar -pczf "$dir/../backup.tar.gz" "$dir/${MyPath}/$line"&>/dev/null
        done
        if [ -f "$dir/../backup.tar.gz" ]; then
                sleep 1
                echo " Success"
        else
                sleep 1
                echo " *** Error ***"
                echo
                echo "***********************************************"
                echo "  *Backup not needed, not replacing anything"
                echo
                echo "***********************************************"
        fi

        echo -n " -Checking App Version..."
        if [ ! "200" == "$myappver" ]; then
                sleep 1
                echo " *** Error ***"
                echo
                echo "***********************************************"
                echo "*** Your app is version $myappver ***"
                echo "*** This file is for 200 ***"
                echo "*** It may not work, please get version 200 ***"
                echo
                echo "***********************************************"
        else 
                sleep 1
                echo " Success"
        fi

        echo -n " -Patching Files..."
        sleep 1
        echo " Success"
        mv -f /hack/* "$dir/${MyPath}/"

        echo -n " -Setting Ownership and Permissions..."
        sleep 1
        echo " Success"
        chmod -R 755 "$dir/${MyPath}/"
        chown -R mobile.mobile "$dir/${MyPath}/"
        if [ $sign = "1" ];then
        ldone "$dir/$binname" -s
        fi

        echo -n " -Cleaning Up..."

        sleep 1
        echo " Success"
        rm -f $gamefiles $hackedfiles $matchingfiles $dirfile
        rmdir /hack

        echo " -Successfully Done :)"
        sleep .5
        echo

        echo "###########"
        echo "# Credits #"
        echo "###########"

        echo " -By SUPERGIU"
        echo
fi

不要制作两个脚本。只需在scipt开始时将
it.lproj/
存储在变量中,即在
之后添加
MYPATH='it.lproj/'
/bin/bash
。然后,通过脚本,将出现的
it.lproj/
替换为
$MYPATH
。这样,当您想从一个版本的脚本切换到另一个版本时,只需执行
MYPATH='it.lproj/'
MYPATH='
谢谢,但请向下查看注释。我只需要一个脚本,可以同时运行这两个脚本,因为它将在.deb中运行,所以我不能/不希望看到哪个脚本运行。再次感谢!然后只需执行
/script1/脚本2
?嗯?抱歉,正如我所说,我完全不懂脚本:(你能给我举个例子(或者用我的两个脚本)谢谢,但是这个脚本会在deb中自动运行(作为POSTNST)所以我不能决定运行哪个脚本。我需要一个脚本,它可以在一个脚本中自动运行两个脚本,如果我理解你的话……那么如何编写一个在第一个脚本和第二个脚本之后运行的脚本呢?是的,这很好,但我不知道如何执行。(这些脚本是用程序生成的,我没有编写它们)抱歉,我不太擅长编写脚本,因为我刚刚在某个地方编写了另一个脚本,它位于其他2个脚本的同一目录中(不需要,但更简单),调用它,例如,
Run2.sh
并在
/bin/bash MyScript1.sh
内和第二行
/bin/bash MyScript2.sh
中写入。保存并从该目录写入后
/bin/bash Run2.sh