Skip to content

Tag: shell

Check for substring in Shell without Bashisms

I’m trying to write a shell script, and in it I have to look for the presence of -32 in a string. Unfortunately I have to do it without using any bashisms as it has to run on computers running Dash. I tried case ${1+”$@”} in *-32*);; but that will pick up something like -321. Is there a way …

Bash No such file or directory error

When I do It works fine. But when I do the same thing with I get ~/Desktop/out.txt: No such file or directory. Why? Answer Take the tilde out of the quotes so it can be properly expanded: You can also use ${HOME} if any subsequent part of your path contains spaces and you want to quote the whole path:

Bash script to install AWS CLI tools

I am writing a bash script that will automatically install and configure AWS CLI tools. I am able to install AWS CLI tools but unable to configure it. My script is something like this: I wish to do the configuration using this script too. I wish that I can provide these credentials via script so that it preve…

Use Bash variable within SLURM sbatch script

I’m trying to obtain a value from another file and use this within a SLURM submission script. However, I get an error that the value is non-numerical, in other words, it is not being dereferenced. Here is the script: When I run this as a normal Bash shell script, it prints out the number of procs correc…

Calling shell script from C++

A shell script test.sh is called from C++ code by the command execl(“/system/bin/sh”,”sh”,”test.sh”) After the execution of shell script i need to get back the control to C++, but the shell script is just exiting not executing the next instructions in C++ code Answer You wa…

Get MAC address using shell script

Currently all the solution mentioned for getting the MAC address always use eth0. But what if instead of eth0 my interfaces start with eth1. Also on OS X the interface names are different. Also the interface eth0 may be present but is unused. i.e. not active, it doesn’t have an IP. So is there a way I c…