Skip to main content

Syntax error while calling a function [Resolved]

So I tried making a function in a script that creates a new variable for each argument when running the script. This is my code:

#!/bin/bash

# Creating function log
#ARG1=${1}

log() {
  echo "You called DA LOG FUNCTION!!!1!!11one111!"
}

log

#echo "${1}"
#echo "$ARG1"

fcta() {
  for ((x=0;x<1000;++x)); do
   "a$x"=${1}
   if [[ ${#} -gt 1 ]]; then
     shift
   else
     x=1001
   fi
  echo "${a$x}"
#  echo "${1}"
}

fcta $@

I get this:

vagrant@localhost vagrant]$./luser-demo10.sh 12 12 12
You called DA LOG FUNCTION!!!1!!11one111!
./luser-demo10.sh: line 25: syntax error near unexpected token `}'
./luser-demo10.sh: line 25: `}'
[04:11----------------------------------------
vagrant@localhost vagrant]$

So this is line 25

#  echo "${1}"
} <----- LINE 25

fcta $@

EDIT: Thanks for telling me about the missing "done". People asked what I was trying to do, well I asked another question for that, since this one has been answered (question was, why did I get a syntax error). Thanks again.


Question Credit: iamAguest
Question Reference
Asked August 22, 2018
Tags: bash, function
Posted Under: Unix Linux
5 views
2 Answers

Your Answer
D:\Adnan\Candoerz\CandoProject\vQA