I have written a C code as given below for decrypting an encrypted string, using popen for the purpose.
snprintf(cmdcheck,1000,"echo %s %c openssl aes-256-cbc -d -a -salt -pass pass:excel2012", idcheck,'|');
FILE *cmdid = popen(cmdcheck,"r");
The code complies well, but on running gives the following error:
sh: Syntax error: "|" unexpected
What can be done to resolve the issue? Thanks in advance. My operating platform is Linux.
the clue is that the error is coming out of sh - "|" is a reserved character in sh so you need to escape it: '\|' should do it.
Related
In TDengine database, I tried to use taosBenchmark to write binary data with specified length in command line, but I got following error
root#Alex ~ $ taosBenchmark -b int,int,binary(100)
-bash: syntax error near unexpected token `('
what is the correct way to use taosBenchamark to write binary data in command line?
try taosBenchmark -b int,intbinary\(100\)
Q: How do I fix this error, or what is the best way to do this?
Used in a function to determine if any partitions on my loopfs are still being used. Shellcheck gives an SC2276 error for this line of code:
"${ARRAY_PROC_LOOP[index]}"="$( lsof -e /run/user/1000/gvfs | grep
"${ARRAY_LOOPFS[index]}" && wait )" 2>/dev/null
https://github.com/koalaman/shellcheck/wiki/SC2276
This is interpreted as a command name containing '='. Bad assignment or comparison?
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"
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.
When I try executing this using popen it returns this error but when I run this in terminal it works!
popen("ssh -n -f *.*.*.* 'sshfs -o nonempty *.*.*.*:/home/foo/bar/ /foo1/foo2/foo3'", "r");
error:
ssh_exchange_identification: Connection closed by remote host
I use public and private key to ssh without passwords and they work properly as this command run flawlessly in terminal.
I changed it to this :
popen("ssh -n -f *.*.*.* `sshfs -o nonempty *.*.*.*:/home/foo/bar/ /foo1/foo2/foo3`", "r");
It return errors too.
error :
fuse: bad mount point `/foo1/foo2/foo3': No such file or directory
Cannot fork into background without a command to execute.
I also tried escipping the internal "" this way : \" \" but it hangs!
Replace ssh with /usr/bin/ssh, do the same with other commands, like sshfs. Specify the full path of the command, /usr/sbin/foo or whatever the case may be. popen does not necessarily use the same shell you have at the command line to execute commands. Check your documentation.