Bad Substitution error bin/sh - arrays

The following snippet is part of a xyz.sh file
#! /bin/sh
TIMESTAMP=$(date +%Y%m%d-%H%M)
TIMESTAMPACTUAL=$(date +%Y-%m-%d)
set P6_84
VMs=$1
VMsCount=${#VMs[#]}
echo "ARAAY: $VMs"
I am getting bad substitution error for the follwoing statement when I try to run the file as ./xyz.sh
VMsCount=${#VMs[#]}
Please help to debug it.

Related

CMake command query (add_custom_command)

I was using the following command for generating Checksum value, .hex and .bin files.
Unfortunately an error comes in the first.
I'm getting error in generating checksum.
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} --fill; 0xFF;0x0-0x3CFFD;--checksum=__checksum:2,crc16,0x0;0x0-0x3CFFD
COMMAND ${CMAKE_OBJCOPY} --ihex ${CMAKE_SOURCE_DIR}/Output/exe/${CMAKE_PROJECT_NAME}.elf ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} --bin ${CMAKE_SOURCE_DIR}/Output/exe/${CMAKE_PROJECT_NAME}.elf ${BIN_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Output/exe
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
The error pop up as
ielftool error: Missing separator in command line option (expected ';'): "0xFF"
Can anyone help out here? It will be a great help.
Thanks.
I was stucked on the same problem by using ielftool in postBuild via IAR Linux Compiler. At the end I got it running but there are some rules to be considered:
the ";" separator has to be written in quotation marks "';'" ("slash" works also)
last arguments of out-file must be wrapped by ""
spae characters between arguments cause some errors
Example:
/opt/iarsystems/bxarm/arm/bin/ielftool --fill 0xFF';'$FLASH_START-$FLASH_START_HEADER --fill 0xFF';'$FLASH_PROGRAMMCODE_START-$FLASH_PROGRAMMCODE_END --checksum __checksum:4,crc32,0x0';'$FLASH_START-$FLASH_START_HEADER';'$FLASH_PROGRAMMCODE_START-$FLASH_PROGRAMMCODE_END --verbose "$INPUT_FILE" "$INPUT_FILE"
#/opt/iarsystems/bxarm/arm/bin/ielftool --fill 0xFF\;$FLASH_START-$FLASH_START_HEADER --fill 0xFF\;$FLASH_PROGRAMMCODE_START-$FLASH_PROGRAMMCODE_END --checksum __checksum:4,crc32,0x0\;$FLASH_START-$FLASH_START_HEADER\;$FLASH_PROGRAMMCODE_START-$FLASH_PROGRAMMCODE_END --verbose "$INPUT_FILE" "$INPUT_FILE"

libtool command not found

Hi i am trying to build my project in linux. The build procedure is configure, make and make install.
During make i am getting error from libtool as shown below. I am not getting what is the reason for this. Please help me with this.
../../libtool: line 445:: command not found
../../libtool: line 448:: command not found
../../libtool: line 453:: command not found
../../libtool: line 474:: command not found
../../libtool: line 523:: command not found
../../libtool: line 529:: command not found
../../libtool: line 539: syntax error near unexpected token `newline'
../../libtool: line 539: ` case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
Thanks in advance.
At the end of line 445 in the file libtool.c maybe there is a ^M. In order to build, this has to be deleted.

I am getting error "array.sh: 3: array.sh: Syntax error: "(" unexpected"

I have written the following code:
#!/bin/bash
#Simple array
array=(1 2 3 4 5)
echo ${array[*]}
And I am getting error:
array.sh: 3: array.sh: Syntax error: "(" unexpected
From what I came to know from Google, that this might be due to the fact that Ubuntu is now not taking "#!/bin/bash" by default... but then again I added the line but the error is still coming.
Also I have tried by executing bash array.sh but no luck! It prints blank.
My Ubuntu version is: Ubuntu 14.04
Given that script:
#!/bin/bash
#Simple array
array=(1 2 3 4 5)
echo ${array[*]}
and assuming:
It's in a file in your current directory named array.sh;
You've done chmod +x array.sh;
You have a sufficiently new version of bash installed in /bin/bash (you report that you have 4.3.8, which is certainly new enough); and
You execute it correctly
then that should work without any problem.
If you execute the script by typing
./array.sh
the system will pay attention to the #!/bin/bash line and execute the script using /bin/bash.
If you execute it by typing something like:
sh ./array.sh
then it will execute it using /bin/sh. On Ubuntu, /bin/sh is typically a symbolic link to /bin/dash, a Bourne-like shell that doesn't support arrays. That will give you exactly the error message that you report.
The shell used to execute a script is not affected by which shell you're currently using or by which shell is configured as your login shell in /etc/passwd or equivalent (unless you use the source or . command).
In your own answer, you say you fixed the problem by using chsh to change your default login shell to /bin/bash. That by itself should not have any effect. (And /bin/bash is the default login shell on Ubuntu anyway; had you changed it to something else previously?)
What must have happened is that you changed the command you use from sh ./array.sh to ./array.sh without realizing it.
Try running sh ./array.sh and see if you get the same error.
Instead of using sh to run the script,
try the following command:
bash ./array.sh
I solved the problem miraculously. In order to solve the issue, I found a link where it was described to be gone by using the following code. After executing them, the issue got resolved.
chsh -s /bin/bash adhikarisubir
grep ^adhikarisubir /etc/passwd
FYI, "adhikarisubir" is my username.
After executing these commands, bash array.sh produced the desired result.

OpenGrok: ClearCaseRepository not working (missing binaries?)

When starting Catalina run, I get the following warning:
WARNING: ClearCaseRepository not working (missing binaries?):
Any idea, anyone?
Thanks, Avi
This is similar to this thread (I will adapt the following extract to your case):
As far as I can see from the code, this warning can only happen if the command "git --help" [in your case cleartool -version] exits with a non-zero exit code.
What do you see if you log in as the tomcat user, set the PATH like you do in startup.sh, and then execute following commands
cleartool -version
echo $?
Check the logs (catalina.out) after adding the following line to your Tomcat's conf/logging.properties:
org.opensolaris.opengrok.level=ALL

tcshrc setting path getting error

im trying to set the environment path to run pintos command like this in my home floder under ubuntu
set path = ($path /home/pintos/src/utils)
and I type terminal command try to compile this
:~$ source .tcshrc
but it seems get error like this
bash: .tcshrc: line 1: syntax error near unexpected token `('
bash: .tcshrc: line 1: `set path = ($path /home/pintos/src/utils)'
I dont know where is the syntax error is ...
You source your script, which is perfectly valid for [t]csh, into your running shell, which happens to be bash (and not tcsh).
If you're going to use tcsh, just run it (by typing tcsh) and ensure that your ~/.tcshrc has the desired effect. (Then, maybe, use chsh to change your login shell).
If you're going to use bash, set path using PATH=$PATH:/home/pintos/src/utils, in ~/.bashrc and/or in ~/.bash_profile.

Resources