Trying to figure out operating system to run a command in my package. Found this :
case "$OSTYPE" in
solaris*) echo "SOLARIS" ;;
darwin*) echo "OSX" ;;
linux*) echo "LINUX" ;;
bsd*) echo "BSD" ;;
msys*) echo "WINDOWS" ;;
*) echo "unknown: $OSTYPE" ;;
esac
I receive : The term 'case' is not recognized as the name of a cmdlet, function, script file, or operable program
But if I run this within a file "sh test.sh" it shows the correct system to terminal.
My operating system is windows. The question is why is the error being received when i run in the terminal and not from the file? And is there any way a case command to run in a script to figure out the operating system?
It looks like that comes out of a UNIX shell script.
You are running windows.
if you are trying to run that thing with cmd, you're gonna have a bad time.
However, you could install a copy bin /bin/sh on your windows box. Such miracles happen these days. Even the crippled operating systems can have a decent shell!
Related
Running this: C:\Projects\HelloWorld>php vendor\bin\codecept generate:cest acceptance createTodo
Results in the Error:
if [ -d /proc/cygdrive ]; then
case $(which php) in
$(readlink -n /proc/cygdrive)/*)
# We are in Cygwin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
;;
esac
fi
"${dir}/codecept" "$#"
I just found the answer at the bottom of some git commentsection and wanted to make it more accessible.
https://github.com/Codeception/Codeception/issues/3281
thx test1git1
The fix to run it on windows is to run the .bat file to do all the commands and drop the "php" at the start.
vendor\bin\codecept.bat generate:cest acceptance createTodo
I have a script I've been working on for installing arch Linux. I have been testing the script in a VM running in windows. when I have been testing parts in the VM and been writing it in windows. the applications I have been using is Notepadd++ in windows and vim on the Linux VM. The part that fails is the for loop in the beginning everything else runs as intended. if i write the for loop in linux it woks. If I write it in windows and copy it over(via github), that part gets skipped like it was never there but I can see it is I look at it in vim. writing it in windows has been the main way I've been writing the script so I really don't know why only this part is having issues.
Link to script on github
part that is not working right
ARGCASE="CHECK"
VMINSTALL="FALSE"
RSAUPASS="FALSE"
for arg in "$#"
do
case $ARGMODE in
CHECK)
case $arg in
-u | --username)
ARGMODE="USERNAME"
;;
-p | --userpass | --userpassword)
ARGMODE="USERPASS"
;;
-r | --rootpass | --rootpassword)
ARGMODE="ROOTPASS"
;;
-vm)
VMINSTALL="TRUE"
;;
-h | --help | *)
echo "This Script is for automating the install of arch linux"
echo "-u\t--username\n\tSet the user name of the users account"
echo "-p\t--userpass\t--userpassword\n\tSet the user password of the users account"
echo "-r\t--rootpass\t--rootpassword\n\tSet the root user's password"
echo "-vm\n\tThis is for when instaling to a virtual machine as some items are not needed since host machene takes care of them"
echo "-rsau\n\tSet Root user password to be the same as user\n\tNOTE: This is not recomended as this could be a security risk"
echo "-h\t--help\n\tshow this text"
exit 0
;;
esac
;;
USERNAME)
USERNAME=$arg
;;
USERPASS)
USERPASS=$arg
;;
ROOTPASS)
ROOTPASS=$arg
;;
esac
done
Using a windows computer to compose a bash script can lead to encoding problems.
If you choose to use windows text editors and then transfer that document to a Unix machine such as Linux you must change the encoding.
There is a built in tool called dos2unix for this.
Run dos2unix then try again.
First variable is listed as ARGCASE while all other references is listed as ARGMODE. Not using the right variable caused a loop that will not do anything as ARGMODE has nothing and ARGCASE has the appropriate value to get the case to work as intended.
I'm attempting to script a process to open two additional shell windows and send commands to them to run some node modules I have installed. This is my first time doing bash scripting so if I'm screwing something up please feel free to let me know.
I have this script
#!/bin/bash
# [-g]
# [-h]
# [-l <location to start the http-server on --default ./>]
# [-p <port to start the http-server on --default "8111">]
run_gulp=false
run_http=false
run_http_port=8111
run_http_location=./
while getopts ghl:p: opt; do
case $opt in
g)
run_gulp=true
;;
h)
run_http=true
;;
l)
run_http_location=$OPTARG
;;
p)
run_http_port=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
if [ $run_gulp == true ]
then
start mintty "gulp" # this works
fi
if [ $run_http == true ]
then
start mintty "http-server $run_http_location -p $run_http_port"
fi
I have it in a file called startdev in a folder that is on my PATH variable (I'm on Windows 10), so I can open up a shell from anywhere and type in startdev -g or startdev -g -h to run this.
This all works, wonderfully I might add, when it opens the shell and sends the gulp command, it detects my gulpfile and is able to run the default task on it like I want it to. However, the http-server isn't doing the same thing, it just tells me http-server ./ -p 8111: No such file or directory.
Mintty treats the first argument as command name, with all the options you pass because of qoutes. Arguments to program started by other program (i. e. with sudo, screen, etc) are usually passed as separate arguments to avoid parsing, so you should try start mintty http-server $run_http_location -p $run_http_port, without quotes.
I am creating an application installer for Mac. The installer involves getting a code from the user on install. I used an Installer Plugin for the Code Input screen.
I have read (from this link) and verified that plugins do not work in the command line and Apple Remote Desktop. I can check if the installer is running from the command line using a variable ("$COMMAND_LINE_INSTALL").
My questions is, how can I programmatically check if it is running via Apple Remote Desktop?
If pstree is available, you can get a quick ancestry of the current process and see if Apple Remote Desktop is in it, something like pstree -p $$ in bash. Unfortunately, I installed pstree using brew, so this is most likely not going to be available for you, unless you distribute a binary yourself.
The other approach is to walk up the parent yourself. Here is a sample that I tested to be working to check if I am running inside iTerm (I used iTerm as a sample because I don't know what the pstree output would look like when running inside Apple Remote Desktop).
pid=$$
running_in_iterm=0
while [ $pid -ne 1 ]; do
command=$(ps -o command= -p $pid)
case "$command" in
*iTerm*)
running_in_iterm=1
break;;
esac
pid=$(ps -o ppid= -p $pid)
done
if [ $running_in_iterm -eq 1 ]; then
echo "Running in iTerm"
else
echo "Not running in iTerm"
fi
You can try running this script from both the built-in Terminal app as well as iTerm and see the difference.
You have to excuse me if I use the wrong language here of if I'm asking an obvious but that is, after all, why I'm here.
I'm just getting to grips with shell scripting and have written a small script that is "Run as a custom command instead of my shell" to make things a little easier for the things I might want to do. Here's what I've got.
#
# Custom console startup script.
#
path_to_scripts=~/Scripts
echo "Hello $USERNAME, what would you like to do?"
echo "Options:"
echo "-l Continue in local machine"
echo "-s Connect to server"
read response
case $response in
"l") echo "Contunie within local machine.";;
"s") $path_to_scripts/connect_to_server;;
*) echo "Invalid command. Exiting.";;
esac
So my terminal starts up with this script and if I select 's' it runs the 'connect_to_server' script fine and connects then I'm in!
However when I enter an invalid command, or key in 'l' to exit and continue as normal the console says 'The child process exited normally with status 0.'
I know that it has just quit and the script has exited but what I want to do is just run the default shell so that I am then in my local machine at ~, as if id just started up console with default settings. What do I need to run in order to do this?
Run exec "$SHELL" to replace the current process with your normal shell.