I want to automate the run of the ./configure command. When I normally run it, every time I have to press enter. I want to run this command from a shell script and I don't want it to wait for a user to press enter at each prompt for path. How do I achieve this ? I am using Ubuntu machine with bash shell. Thanks.
mdt-inference#ubuntu:~/MDT/mdst-libreoffice$ ./configure
Path to Office installation? [/usr/lib/libreoffice]
Path to Office SDK installation? [/usr/lib/libreoffice/sdk]
Note : I tried the below link but it does not work.
How to simulate two consecutive ENTER key presses for a command in a bash script?
I have used "yes" command already but when I run ./configure there are multiple prompts which are more than two. When I use "yes", it just supplies argument to the first prompt only
yes command can be used here (with just 2 enter key)
yes " " | head -2 | ./configure
In general, this should work.
yes | ./configure
You might check out the cram Python package:
https://pypi.python.org/pypi/cram
It's designed for straightforward automation of command-line apps, and I've been pleasantly surprised by how well it's worked for my needs so far.
Related
Trying to run a curl command on macos terminal which I was able to run from a windows command prompt. The curl command is relatively long with multiple "--data-urlencode" flags (5 total) and then the final -v flag. On windows, I can simply copy/paste the command to the command prompt or powershell, press Enter, and it runs fine. However, on macos terminal using zsh, the command prompt just shows a reverse prompt after I try to press Enter. It's as if it is waiting for more input or some other run command which I am not aware of.
On macos, I have been able to run shorter curl commands without any issues, but when I paste in a relatively longer curl command, I am presented with more prompts as if zsh doesn't realize the command input is done. I have also tried to manually type out the command to see if copy/paste is the issue, but same problem. I have also tried to change the order of the flag options, but that doesn't make any difference either. I have googled the heck out of this, but alas - no joy.
On Windows, if I start c:\msys64\mingw64.exe, it opens a shell, where I can build my project, let's say by calling a release bash script (to simplify). Everything works fine.
Now, I would like to execute my release script on mingw64 directly, without interaction.
I tried:
c:\msys64\mingw64.exe /c/the/full/path/release
A window opens and closes, it does not work.
I attempted to use bash directly, but it seems the environment is not correctly set:
> c:\msys64\usr\bin\bash -c ls
/usr/bin/bash: ls: command not found
> c:\msys64\usr\bin\bash -c /bin/ls
... it works ...
So it is obvious that the environment is not the same as when execute c:\msys64\mingw64.exe then call ls.
How to execute my release script as if I were in the shell started by mingw64.exe?
To run a Bash shell script in MSYS2 without showing a window, you should right-click on your Desktop or somewhere else in Windows Explorer, select "New", select "Shortcut", and then enter something like this for the shortcut target:
C:\msys64\usr\bin\mintty.exe -w hide /bin/env MSYSTEM=MINGW64 /bin/bash -l /c/Users/rom1v/project/release.sh
Note that there are 4 paths in here. The path to mintty and release.sh are absolute paths that you will need to adjust. The paths to env and bash are relative to your MSYS2 installation directory. Note also that the first path must be a standard Windows path, since Windows expects that when it is running a shortcut.
Explanation
It might seem odd to use MinTTY for a non-interactive script, but we need to use some program that was compiled for the Windows subsystem (-mwindows option to GCC), or else Windows will automatically start a new console when we run the program. We pass the -w hide option to MinTTY to tell it not to actually show a window. Everything after that option is interpreted by MinTTY as a command to run.
So MinTTY will run /bin/env from the MSYS2 distribution and pass the remainder of the arguments on to it. This is a handy utility that is actually a standard part of Linux as well as MSYS2. It sets the MSYSTEM environment variable to MINGW64 (which is important later) and then it runs /bin/bash with the remainder of the command-line arguments.
We pass -l to Bash so that it acts as a login script, and runs certain startup scripts. In particular, the /etc/profile script from MSYS2 is essential because it looks at the MSYSTEM environment variable, sees that it is MINGW64, and then sets a bunch of other environment variables (e.g. PATH) to give you the MinGW 64-bit shell environment.
Finally, we pass the name of your script as the main argument to bash, so it will run that script after running the initialization scripts.
Error handling
Note that if your Bash script has an error, you won't get any notification, because the shortcut above doesn't open any console windows. I personally would find that pretty annoying. I'd probably remove the -w hide option, then make a wrapper bash script that just does something like:
run_my_main_script || sleep 10000
So if the main script is successful, exit right away, otherwise keep the window open for 10000 seconds. You don't have to even put that wrapper script in its own file, you can just put it in the shortcut as the argument to Bash's -c option (don't forget to wrap it in double quotes).
Thanks to the answers from #David Grayson, I managed to call my release script with msys2/mingw from a Windows console (cmd), with additional directories (for Java and Meson) in $PATH:
c:\msys64\usr\bin\env MSYSTEM=MINGW64 c:\msys64\usr\bin\bash -l -c "PATH=\"/c/Program Files/Java/jdk1.8.X_XXX/bin:/c/Program Files/Meson:$PATH\" /c/Users/rom1v/project/release"
add an supplement to the above: if u want to the output of shell script
reference:https://mintty.github.io/mintty.1.html
-l, --log FILE|-
Copy all output into the specified log file, or standard output if a dash is given instead of a file name. (Implies -o Logging=yes.)
If FILE contains %d it will be substituted with the process ID. See description of equivalent option "Log file" (Log=) below for further formatting options and hints.
Note that logging can be toggled from the extended context menu.
Add A complete example:
C:\msys64\usr\bin\mintty.exe -w hide -l - c:\msys64\usr\bin\env MSYSTEM=MINGW64 c:\msys64\usr\bin\bash -l -c "PATH=\"$PATH\" /C/Users/Administrator/Desktop/myProject/Demo_C_C++/shell/textProcess/bookNoteHandler.sh" | find /v "/v:Displays all lines that don't contain the specified"
=========
I'm trying to create a script to check if Homebrew is installed on any given mac and in case it is if it has a particular formula installed. I have the part that checks if brew is installed, but when I try to run brew list to see what packages are installed I get "Command not found" even though I can run the command in the Terminal fine. I'm using:
do shell script "brew list"
Is there any other way to run brew commands in Applescript?
It's best to call the command directly, otherwise AppleScript might not find the correct path returning command not found — To do that you'll want to see where the brew command is located in Terminal:
$ which brew
/usr/local/bin/brew
Based off of this you should be able to do:
do shell script "/usr/local/bin/brew list"
If you have multiple arguments after a command use the -c option:
do shell script "/usr/local/bin/brew -c list <package>"
If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with $0.
If you wanted a complete way to figure out the path you might be able to do something such as:
set brewPath to do shell script "/usr/bin/which brew | awk '{print $0}'" as string
set brewList to do shell script "" & brewPath & " list" as string
*note: I haven't tested this, so it might require some adjustment.
I'm a complete novice at this (terminal in Mac leopard) and hoping to get an lifeline from the web as I've certainly hit a wall.
I want to run a script as a root in terminal. The script is saved as a text file with a .rtf extension. I've inserted into terminal:
sudo filename.rtf
then I get asked a password which I've typed in (admin password) and pressed enter; then it shows a prompt: sudo: Mac: command not found
I've tried it with the extension hidden but got the same result. Any pointers on what I'm doing wrong?
Thanks in advance
You need to first get the script out of the .rtf file and into a plain text file (open it up in TextEdit and select "Make Plain Text" from the format menu, then save it again as myscript.sh).
Now you can type
sudo sh myscript.sh
The "magic" sh letters there are because as another responder says, sudo will temporarily elevate you to superuser and run a program. In *nix environments, that would be anything with the executable bit set, meaning that someone's explicitly told the operating system that it's safe to run a file. In your case, your myscript.sh has not been "blessed" in this way, so to run it you need to feed it into a program that knows how to understand it. That program is sh, and it does have the executable bit set. Thinking of it as sudo (sh myscript.sh) might make it a bit clearer.
If you plan on running this script a lot, you might want to actually make it executable on its own. This amounts to putting special instructions inside the file that tell the operating system how the file should be run. If you stick #!/bin/sh (this is called a shebang line and tells the OS what to do with your file) on the first line of your script, and then type chmod u+x myscript.sh (this tells the OS that you, and only you, are allowed to execute your file), you'll be able to run the file directly with sudo myscript.sh.
sudo is used to execute commands as the root user of the machine.
when you type
sudo [somthing]
the shell grants temporary root privilges and then executes the given "somthing"
assume your script is in bash, you should have done
sudo sh filename.rtf
Also, it's better to save script as plain txt, with an sh extension, so you would execute
sudo sh myscript.sh
first set the script as executable:
chmod +x filename.rtf
Then you can run it like so:
sudo ./filename.rtf
I am trying to run growlnotify from inside a ruby script.
The command I am using is this system("growlnotify Test -m message").
If I use the terminal to execute the script it works fine. If I use Textmate to run the script or Geektool (the eventual target of the script) it does not ever run the growlnotify part. Each other part of the script runs using Textmate or Geektool, but only using the terminal causes Growl to launch a notification window.
Anyone used this tool before?
Is growlnotify in the PATH that TextMate uses?
Try passing the complete path to growlnotify: ie /usr/local/bin/growlnotify
A backtick is the little apostrophe like mark on the same key as the tilde.
`growlnotify -m message`
does the same thing as
system("growlnotify -m message")
except it also gives you the output of the command.
Another variation is
%x{growlnotify -m message}