Skip to content
Advertisement

Tag: bash

How to make GREP select only numeric values?

I use the df command in a bash script: This script returns: But I need only numbers (to make the next comparison). If I use the grep regex without the dot: I receive nothing. How to fix? Answer If you try: It returns: Here’s the details on the -o (or –only-matching flag) works from the grep manual page. Print only

Bash: executing commands from within a chroot and switch user

Im writing a script that should do this… I have tried this approach: This tries to execute the user switching and the script as a string command to bash…however what it does, is it “stops” after “su -” and doesnt execute the script. However, once I leave the “su -” environment, it does try to run startup.sh but of course,

Difference between bash pid and $$

I’m a bash scripting beginner, and I have a “homework” to do. I figured most of the stuff out but there is a part which says that I have to echo the pid of the parent bash and the pid of the two subshells that I will be running. So I looked online and found this (The Linux documentation project):

pass stdout as file name for command line util?

I’m working with a command line utility that requires passing the name of a file to write output to, e.g. The only thing it writes to stdout is a message that indicates that it ran successfully. I’d like to be able to pipe everything that is written to output.txt to another command line utility. My motivation is that output.txt will

Error installing NPM for node.js

I’m trying to install npm on ubuntu 11.04 using the “git all the way” method found in this gist I keep getting this error after running sudo make install on npm I know this is something wrong with bash, but I’m not very good with bash. EDIT running the node command in the terminal brings up the node shell as

Check if mysql database exists, perform action based on result

Is it possible from within a bash script to check if a mysql database exists. Depending on the result then perform another action or terminate the script? Answer Example script (Thanks to Bill Karwin for the –user and –password comment!): These are what the commands look like when run at a prompt: If no DB exists, the output will look

basename with spaces in a bash script?

I’m working on a bash script to create a new folder in /tmp/ using the name of a file, and then copy the file inside that folder. Behavior: When I type in mymove “/home/me/downloads/my new file.zip” it shows this: I have lots of quotes around everything, so I don’t understand why this is not working as expected. Also, I have

Correct way to build “live” directory structure after maven build?

I have a multi module maven project which looks something like: main component_one subcomponent_bob subcomponent_mike subcomponent_joe component_one_aggregate component_two subcomponent_tim subcomponent_lary component_two_aggregate The aggregate projects create parent jars for each of the components containing all of their subcomponents. I have a pom in each directory, and it all deploys to a local repository. Everything works great! Except that I would like

Bash/sh ‘if else’ statement

I want to understand the if else statement in sh scripting. So I wrote the below to find out whether JAVA_HOME is set in the environment or not. I wrote the below script This my output to env: But I get the below output: Answer You’re running into a stupid limitation of the way sh expands arguments. Line 3 of

Advertisement