LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help fix my script. syntax error: unexpected end of file (https://www.linuxquestions.org/questions/linux-newbie-8/help-fix-my-script-syntax-error-unexpected-end-of-file-4175470237/)

imadork8317 07-19-2013 03:20 PM

Help fix my script. syntax error: unexpected end of file
 
This is probably simple and i probably am not doing this in the most elegant fashion, so any help would be appreciated. When i run the script it works fine but at the end i receive the follow message

"line 16: syntax error: unexpected end of file"

Here is my script

Quote:

#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
[Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
[Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
[Yy]* ) read -p "What is the Android dylib version? " DYLIB; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
read -p "Is the Android app version ${DYLIB}?" yn
case $yn in
[Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
[Nn]* ) read -p "what is the Android app version? " APP; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
[Nn]* ) ;;
esac

Firerat 07-19-2013 03:27 PM

use code instead of quote for code.

anyway..

see bold comment
Code:

#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
    [Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
    [Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
# the below line is 'broken', should end ;; not ;
    [Yy]* ) read -p "What is the Android dylib version? " DYLIB; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
read -p "Is the Android app version ${DYLIB}?" yn
case $yn in
    [Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
    [Nn]* ) read -p "what is the Android app version? " APP; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
[Nn]* ) ;;
esac


Firerat 07-19-2013 03:31 PM

you might be better using select/ case instead of read/ case

jonesr 07-19-2013 03:34 PM

Think through what you are intending as the logical flow of the case statements you are starting on lines 8 and 11. Indenting your code may help. One of those case statements is never closed. The shell expects more but hits the end of the file.

imadork8317 07-19-2013 03:40 PM

Quote:

Originally Posted by Firerat (Post 4993437)
use code instead of quote for code.

anyway..

see bold comment
Code:

#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
    [Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
    [Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
# the below line is 'broken', should end ;; not ;
    [Yy]* ) read -p "What is the Android dylib version? " DYLIB; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
read -p "Is the Android app version ${DYLIB}?" yn
case $yn in
    [Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
    [Nn]* ) read -p "what is the Android app version? " APP; ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
[Nn]* ) ;;
esac


If i close line 9 with ';;' then the read statement will not be included and will through a syntax error

imadork8317 07-19-2013 03:42 PM

Quote:

Originally Posted by Firerat (Post 4993438)
you might be better using select/ case instead of read/ case

What is the advantage to use select vs read?

imadork8317 07-19-2013 03:52 PM

Think i fixed it. I had to close the case after esac on line 17

Code:

#!/usr/bin/env bash -x
read -p "Update iOS dylib and app? " yn
case $yn in
    [Yy]*) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com upgrade_all";;
    [Nn]*) ;;
esac
read -p "Update Android dylib and app? " yn
case $yn in
    [Yy]* ) read -p "What is the Android dylib version? " DYLIB;
            ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -d ${DYLIB} -a";
            read -p "Is the Android app version ${DYLIB}?" yn;
                case $yn in
                    [Yy]* ) ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${DYLIB} -a";;
                    [Nn]* ) read -p "what is the Android app version? " APP;
                            ssh mnadmin@contoso.com "/home/mnadmin/ops/tenant_admin/tenantcfg.rb -a https://contoso.com setver_all -m ${APP} -a";;
                esac;;
    [Nn]* ) ;;
esac


David the H. 07-21-2013 09:12 AM

One of the more useful concepts in scripting is keeping your data separate from your code as much as possible.

One of the primary ways to do this is to pre-define all of your file paths and other fixed data strings in variables at the top of the script, rather than embedding them in the script. It keeps the clutter down and makes things cleaner and easier to debug, as well as making them easier to alter without having to go through the whole script.

Specifically, the following three strings of yours should all be pre-configured as variables:

mnadmin@contoso.com
/home/mnadmin/ops/tenant_admin/tenantcfg.rb
https://contoso.com

In addition, since the same ssh command appears over and over with only minor variations, that makes it a perfect candidate for a function. preconfigure the basic command at the top of the script, and call it with the proper options when the need arises.

Check out Scripting With Style for more tips on how to write clean and robust code.


All times are GMT -5. The time now is 06:41 PM.