bash

How to do a search for PID? (bash)

Hi, assuming that I know the PID of a process and want to do a search in ps -A, how do I do it? I tried doing this: echo "Enter PID to search: " read PID search=$(ps -A | grep -v PID | awk '{print $1}') This returns me with a long list of PIDs. So how can I get use each individual value of the output and do: if [ "$PID" = "*each_val...

How can I keep a file in memory during editing?

Short version : echo "testing" | vim - | grep "good" This doesn't work as vim won't output to a pipe. It says : "Vim: Warning: Output is not to a terminal". Any way to do this? Cross-editor support would be nice too. I've tried named pipes, but vim won't open them. Long version : echo $passw | gpg -q -d --passphrase-fd 0 $filename | v...

if .bash_profile usually source .bashrc any way, why not just use .bashrc ?

it seems that we will put source ~/.bashrc in our .bash_profile anyway. So why not just use one file, say .bashrc ? ...

How to do a script in BASH which takes random text from file?

I have file like: aaa bbb ccc ddd eee And I want to do a script in BASH which can takes random line of this text file, and return it to me as variable or something. I hear it can be done with some AWK. Any ideas? UPDATE: I now using this: shuf -n 1 text.txt Thanks you all for help! ...

Detect if shell script is running through a pipe

How do I detect from within a shell script if its standard output is targetting a terminal or if it's piped to another process? (Case in point: I'd like to add escape codes to colorize output, but only when run interactively, but not when piped, similarly to what ls --color does.) ...

Argument Checking Problem in Bash Script

So basically I am trying to check the arguments that are passed into the script. If it has three arguments and the third argument is a 1, then I want it to continue. I also want it to continue if it has four arguments and the third argument is not a 1. So basically I thought that I could just do... if ([ $# -ne 3 ] and [ "$3" -ne "2"...

Is it normal for "rsyslogd" to cost 170M memory?

One of my sites runs extremely slow, and I use top command to see that "rsyslogd" cost 170M memory, is that normal? If not,how can I limit the size of memory "rsyslogd" cost,or the frequency the "rsyslogd" runs? ...

Bash shell for Windows?

Is there anything like bash shell in Windows with at least basic set of frequently used commands like ls, pwd, tail, etc? ...

how to evaluate a given path within a bash shell

Hi all, Is there a bash command that takes as input a file path and returns an absolute file path? More specifically I would like a command that takes as input a path such as: /tmp/yaneeve/kit/linux/../../output/kit/SOURCES//usr//apps/myapp/lib and returns the path: /tmp/yaneeve/output/kit/SOURCES/usr/apps/myapp/lib Thanks! ...

how to look up which files a certain process is manipulating?

In my case it's "rsyslogd", I find it's consuming up to 170M memory,which is too much, and I've checked its configuration file located at /etc/rsyslog.conf and then checked each file written inside it, but in vain. How can I look up the file it's currently manipulating and look inside what's going on? [root@slvdb2 log]# lsof -p `pi...

Can ${var} expressions be nested in bash?

What I have is this: progname=${0%.*} progname=${progname##*/} Can this be nested (or not) into one line, i.e. a single expression? Basically I'm trying to strip the path and extension off of a script name so that only the base name is left. The above two lines work fine. My 'C' nature is simply driving me to obfuscate these even m...

Split string based on delimiter in bash?

How to split string based on delimiter in bash? I have this string stored in a variable: IN="[email protected];[email protected]" Now I would like to split the strings by ';' delimiter so that I have ADDR1="[email protected]" ADDR2="[email protected]" Don't necessarily need ADDR1, ADDR2 variables, if they are elements of an array that's even better...

Bash condition of the form - [ -n "${VAR:-x}" ] gets evaluated even though VAR is set

Hi all, I have written an if statement of the form: if [ -n "${VAR:-x}" ]; then #do something export VAR=#something fi My shell script calls this statement twice and surprisingly passes the condition twice. [hint (perhaps...): This exact code is repeated in a function in an included file. The if statement is first evaluated pr...

How to get script file path inside script itself when called through sym link

Hi, When I need to get path to the script file inside script itself I use something like this: `dirname $0` that works file until I call the script through sym link to it. In that case above code prints the location of the link instead the original file. Is there a way to get the path of the original script file, not the link? Than...

Unable to find a substitute command for Bash's complete in Zsh

I put the newest git-completion.bash to my .zshrc and I get /Users/Masi/bin/shells/git/git-completion.bash:2116: command not found: complete /Users/Masi/bin/shells/git/git-completion.bash:2118: command not found: complete The lines are complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \ || complete -o defaul...

How do I program using cat?

In this xkcd comic: they mention that real programmers use cat. Well, I was asking myself: how could you program using the cat command? ...

Run lynx -dump in background?

I have a bash script mystuff containing a line like lynx -dump http://example.com >tmpfile and the script works fine, including this part, except when I run it non-interactively: $ ./mystuff & [1] 3712 $ jobs [1]+ Stopped The job is stopped. I find that lynx is the culprit. Even running this command directly from the bash prompt ca...

How can I replace mutliple empty lines with a single empty line in bash?

I have a file that contains: something something else something else again I need a bash command, sed/grep w.e that will produce the following output something something else something else again In other words, I need to remove multiple blank lines with just a single blank line. gred/sed are line based. I've never found a BA...

Set effective group id of Perl script

I have file permissions issues that I would like to resolve without resorting to making everything world writable. I'm writing files to a NetApp SAN. The directory I'm writing to is owned by the devel user, and has a group of devel with group-writable permissions (0775). The username I'm writing as is in the username and devel groups. ...

How do I write a bash alias/function to grep all files in all subdirectories for a string?

I've been using the following command to grep for a string in all the python source files in and below my current directory: find . -name '*.py' -exec grep -nHr <string> {} \; I'd like to simplify things so that I can just type something like findpy <string> And get the exact same result. Aliases don't seem sufficient since they on...