Visit The New, Modern Unix Linux Community

Syntax error: Unexpected '('

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax error: Unexpected '('
# 1  
[SOLVED] Syntax error: Unexpected '('

I've been trying to figure this issue for almost 2 hours now...
I dont see/find any typos or other code mismatches.. but maybe i'm looking at the wrong places....

Here's the console output:
[sea@manjaro-desktop ~]$ LC_ALL=C
[sea@manjaro-desktop SWARM]$ cd prjs/SWARM/ ; time source ./rc
bash: cd: prjs/SWARM/: No such file or directory
......bash: /home/sea/prjs/SWARM/data/core/core.adm: line 114: syntax error near unexpected token `('
bash: /home/sea/prjs/SWARM/data/core/core.adm: line 114: `    	traps_save() { saved_traps=\$(trap) ; export saved_traps ; }'
Seems this file could not be loaded: /home/sea/prjs/SWARM/data/core/core.adm
.........: \tWHICH=
: \tPWD_EXEC=pwd
.............. ----------- TEST AREA -----------
 ----------- TEST AREA -----------

real	0m0.102s
user	0m0.122s
sys	0m0.031s
[sea@manjaro-desktop SWARM]$ cat -n /home/sea/prjs/SWARM/data/core/core.adm | grep 114
   114	    	traps_save() { saved_traps=\$(trap) ; export saved_traps ; }

Biggest issue, I know THAT code works 100% fine, as I just copied it from former project (for which I copied it from the manpages)...
So it must be somewhere in the other code.. but to me.. looks fine too...

core.adm file:
#!/usr/bin/env bash
# Prepare LOG and TMP files
    if [[ 0 -eq ${UID:-${EUID:-0}} ]]
    then    # It's ROOT
    else    # It's a user, make sure we save to the right place
            declare tmp_worker
            # Not all mkdirs support creating subdirs...
            [[ -d "$tmp_worker" ]] || $MKDIR "$tmp_worker"
            [[ -d "$SWARM_USER_CONFIG" ]] || $MKDIR "$SWARM_USER_CONFIG"
            unset tmp_worker
            # Actualy set the required variables
    for thisD in $SWARM_LOG_DIR $SWARM_TMP_DIR
        [[ -d "$thisD" ]] || $MKDIR "$thisD"
    # Finalize
    [[ ! -d "$SWARM_TMP_DIR" ]] && $MKDIR "$SWARM_TMP_DIR"
    #$TOUCH "$SWARM_TMP" ## No actual need to create an empty tempfile
# Prepare basic utility functions
    init.msg() { $PRINTF '%s\n' "$1" ;}
    init.log() { ${isRO:-false} && return ; [ -f "$SWARM_LOG" ] || ( $TOUCH "$SWARM_LOG" && >"$SWARM_LOG") ; init.msg "$DATE_TIME_LOG SWARM :: $1" >> "$SWARM_LOG" ;}
    init.log.msg() { init.msg "$1"; ! ${isRO:-false} || init.log "$1";}
    init.log.check() {
    # Checks for log path and logfile
    # Creates if required and prints date and or divider line
        local RET
        if [[ ! -f "$SWARM_LOG" ]]
            # Make sure path exists
            $MKDIR "$SWARM_LOG_DIR"
            ! $TOUCH "$SWARM_LOG" && init.log.msg "${SWARM_MSG_INIT_LOG_FAIL} -> $SWARM_LOG @ uid:${UID:-$EUID}"
        # If todays date was not found, write it
        if $GREP "$DATE_CUR" "$SWARM_LOG" >/dev/null
        then    # Print a visual divider
                init.log " -------------------"  #>> "$SWARM_LOG"
        else    # Date is missing, print that instead
                init.log "$DATE_CUR"

        # Exit function
        return $RET
# Make sure we can differ the date in the log,
# if this fails, no write access, RO?
    # Only check log if loging is enabled (default:true)
    ${doLog:-true} && init.log.check && isRO=false || isRO=true
# Sometimes all that is needed,
# is a propper Clean Up
    # Prints an error message and exits
        caller="\$1" script="\$2" fname="\$3" lineno="\$4"
        shift 4 #2 #4

        content=($($ECHO "\${@}"))
        $PRINTF "\n"
        # The eval is required for the function to work after export
        eval $PRINTF '\t%s:\t%s\n' \\
            "Callerscript" "\$caller" \\
            "Scriptname" "\$script" \\
            "Functionname" "\$fname :: \$FUNCNAME" \\
            "Linenumber" "\$lineno :: \$LINENO"
        for cont in "\${content[@]}";do
            $PRINTF '\t* %s\n' "\$cont"
        # Original
        # Neu
        exit 1
    swarm.cleanup() { #
    # Clears all known variables and sub routines on terminal exit from memory
    # This is for security and proper coding alike
        echo todo cleanup >&2
        unset ${!USER_*}

        for p in $SWARM_PID_THEME
            kill -s SIGKILL $p

        # Delete files
        [[ -f "$SWARM_TMP" ]] && $RM "$SWARM_TMP"

        # This as last for all the user display - and log - messages
        unset ${!SWARM_*}
        unset swarm.*
#	Traps & Error messages
    	traps_save() { saved_traps=\$(trap) ; export saved_traps ; }
    	traps_restore() { eval \$saved_traps;}
    	export -f swarm.error swarm.cleanup traps_save traps_restore
        trap "swarm.error \${CALLER:-\$0} \$0 '\$($ECHO -E \${@})'" ABRT ALRM HUP QUIT TERM

I assume the error cause to be either one of: ", ', (), [] or {} ; but I dont see any mismatches...
Maybe it's something else?

What confuses me is this, it fails on a function.
But there are other functions loaded properly, and the 2 functions above seem fine to me too...

Any thoughts and insights are welcome!
Thank you in advance Smilie

Last edited by sea; 03-10-2020 at 04:43 PM..
# 2  
WTF... why, how?!

It was the 'trap' code... but... I still have no clue what's wrong with it....
For obvious reasons, this works now - commeted 'everything' out....

Maybe those 4 years not coding had a price...
Am I really THAT blind???
#	Traps & Error messages
    	#traps_save() { saved_traps=\$(trap) ; export saved_traps;}
    	#traps_restore() { eval \$saved_traps;}
    	#export -f traps_save traps_restore

What confuses me the most is the fact the just the function above traps_save could be loaded and executed without an issue.
Both start with functionname(), yet... swarm.cleanup works like a charm, while traps_save stoped working...

Thats kind of the reasons why I'm so confused, it the error was earlier... shouldnt it cause issues on other functions that were loaded prior to traps_save?
But it doesnt...

This is burnout stuff - to me...

Last edited by sea; 03-10-2020 at 04:21 PM..
# 3  
You say you were 100% sure this code works. Do you have the exact same environment as before? Same software? Same versions? Probably not.

traps_save() { saved_traps=\$(trap) ; export saved_traps;}

That code fails at my system too.

I assume you'd like to have:
traps_save() { saved_traps="$(trap)" ; export saved_traps;}

This User Gave Thanks to stomp For This Post:
# 4  
Thank you stomp

I was 100% sure...
As it used to work yesterday - or I've must have overseen this message due to all other error messages... Smilie
[sea@manjaro-desktop SWARM]$ grep traps_ ../tui/scripts/*
grep: ../tui/scripts/distro: Ist ein Verzeichnis
../tui/scripts/	traps_save(){ saved_traps=\$(trap) ; export

As you see, it's the exact same code, that had worked for over a year (5 years ago).
Maybe there was a security update or something?

But now thinking about it....
That was to, well, generate an RC file, for which of course the $ had to be escaped....
Now, it's in the actual script already -> no need to escape...

Thanks a bunch again stomp! Smilie


Last edited by sea; 03-10-2020 at 06:21 PM..

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #583
Difficulty: Easy
Buffered input/output is used because I/O operations can slow the system down.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error: `]' unexpected

I am getting this error Syntax error: `]' unexpected. Did I do something wrong with elif? Does ksh not like double brackets? if ]; then #echo hi source ~/.bashrc; elif ]; then #echo hi source ~/.kshrc; fi (5 Replies)
Discussion started by: cokedude
5 Replies

2. Shell Programming and Scripting

Syntax error `(' unexpected

I have written this in my script but while running i am getting syntax error `(' unexpected. unload to "$BACKUP_DIR/n_fac_fid-$clliname" select * from n_fac_fid where fac_accesskey in (select fac_accesskey From n_fac_ap_fid where ap_clli="$clliname"); Any help appreciated. (3 Replies)
Discussion started by: suryanmi
3 Replies

3. Shell Programming and Scripting

Syntax error: 'fi' unexpected

unzip if ] ; then echo "Success" else echo "Some failure." fi ; I tried many time to detect the unzip error, but it keep show the syntax error wherever how I change the syntac. Hope someone can help me fix the issue, thanks. Please use code tags next time for your code and... (5 Replies)
Discussion started by: duncanyy
5 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `}' please help

I'm going mad not being able to get this to work. im assuming its only a simple mistake but its driving me bonkers trying to find it. Please if you can help me it would save me pulling my hair out!! Thanks #!/bin/bash -xv # #Config name="TEST Server" + name='TEST Server'... (6 Replies)
Discussion started by: Fisheh
6 Replies

5. Shell Programming and Scripting

ksh syntax error: `(' unexpected

So I am trying to convert my bash script into ksh, and this is what I have in the file so far: #!/bin/ksh login() { if then sendcmd BETA else sendcmd "$(xxd -c 32 -g 0 ${ZETA_ZETA} | awk '{print $2}')" fi } But when I run it: $ ./ ... (1 Reply)
Discussion started by: guitarscn
1 Replies

6. Shell Programming and Scripting

syntax error: `$' unexpected

Hi all, Am very new to Unix and am currently Involved in Migrating some Shell Scripts from AIX 4 to Solaris 10. While using teh for loop am getting the below error: $ echo $SHELL /usr/bin/ksh $ for file in $(ls *SEBE*) syntax error: `$' unexpected while the same works without issue on... (4 Replies)
Discussion started by: paragkhanore
4 Replies

7. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

8. UNIX for Advanced & Expert Users

Syntax error near unexpected token

Hi, When I run the below shell script I'm getting the error " syntax error near unexpected token `" Script: REM :: File Name : Refresh_OTL.bat REM :: Parameters : %1 - Region REM :: : %2 - Cube Type REM :: : REM :: Notes : REM ============================== set ENVIRONMENT... (2 Replies)
Discussion started by: tomailraj
2 Replies

9. Shell Programming and Scripting

unexpected syntax error

Hi, i am getting following syntax error ...kingly advice why is it coming ?? #!/bin/bash find . -name "common.log" if ; then echo "1" fi Himnashu@home /bin $ ./ ./ line 7: syntax error near unexpected token `fi' ./ line 7: `fi' (9 Replies)
Discussion started by: himvat
9 Replies

10. Shell Programming and Scripting

sh: syntax error: `...' unexpected???

Hello all, I want to create a script that polls every hour a directory for the existence of a file. The file I look for is a `token` dropped by an external process at the completion of a successful FTP process. I wrote this script `checkfile.ksh`: #!/usr/bin/ksh if ] then mailx... (5 Replies)
Discussion started by: alan
5 Replies

Featured Tech Videos