bash

shell script -o operation is not working

DISPLAY_HEADER=1 if [ "$1" != "test" -o "$1" != "test2" ] then if [ $DISPLAY_HEADER == 1 ]; then DISPLAY_HEADER=0 echo "sdasa " echo $1 fi fi its display sdasa and -o is not working ? what is wrong ? ...

awk search on multiple fields of a multi line record file

Hi I have a file with records that are of the form: SMS-MT-FSM-DEL-REP country: IN 1280363645.979354_PFS_1_1887728354 SMS-MT-FSM-DEL-REP country: IN 1280363645.729309_PFS_1_1084296392 SMS-MO-FSM country: IR 1280105721.484103_PFM_1_1187616097 SMS-MO-FSM country: MO 1280105721.461090_PFM_1_882824215 This lends itself to parsing via a...

Shell Script - How to get stuff between two separators

Hi, I've got something like that: xinput --list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Microsoft Basic Optical Mouse id=8 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master...

How do I send multiple results from one command to another in bash?

Hey guys and gals, I'm not sure if this is possible in one line (i.e., without writing a script), but I want to run an ls | grep command and then for each result, pipe it to another command. To be specific, I've got a directory full of images and I only want to view certain ones. I can filter the images I'm interested in with ls | gr...

bash execute a shell function after a change directory (cd)

Trying to find a way to execute a function within BASH after changing into a directory. for example, # cd code/project/blah "Your latest modified files are main.cc blah.hpp blah.cc" (~/code/project/blah) # _ With the above I'm hoping to be able to wrap other functionality around the bash command. Was hoping to find something along t...

shell scripting default value

I am trying to learn shell scripting and I am kind of confused with the idea of := or default value #!/bin/sh echo "Please enter a number \c" read input input=$((input % 2)) if [ $input -eq 0 ] then echo "Th...

bash line concatenation during variable interpolation

$ cat isbndb.sample | wc -l 13 $ var=$(cat isbndb.sample); echo $var | wc -l 1 Why is the newline character missing when I assign the string to the variable? How can I keep the newline character from being converted into a space? I am using bash. ...

Is it possible to make a bash shell script interact with another command line program?

I am using a interactive command line program in a Linux terminal running the bash shell. I have a definite sequence of command that I input to the shell program. The program writes its output to standard output. One of these commands is a 'save' command, that writes the output of the previous command that was run, to a file to disk. A...

Using xargs to assign stdin to a variable

All that I really want to do is make sure everything in a pipeline succeeded and assign the last stdin to a variable. Consider the following dumbed down scenario: x=`exit 1|cat` When I run declare -a, I see this: declare -a PIPESTATUS='([0]="0")' I need some way to notice the exit 1, so I converted it to this: exit 1|cat|xargs -I {...

Echo expanded PS1

I have a shell script that runs the same command in several directories (fgit). For each directory, I would like it to show the current prompt + the command which will be run there. How do I get the string that corresponds to the decoded (expanded)PS1? For example, my default PS1 is ${debian_chroot:+($debian_chroot)}\[\e[1;32m\]\u\[\e[0m...

How do I use output from awk in another command?

So I need to convert a date to a different format. With a bash pipeline, I'm taking the date from the last console login, and pulling the relevant bits out with awk, like so: last $USER | grep console | head -1 | awk '{print $4, $5}' Which outputs: Aug 08 ($4=Aug $5=08, in this case.) Now, I want to take 'Aug 08' and put it into a d...

Call C function in Bash script

Related to question 3451993, is it possible to call a function which is internal to subst.c (in the Bash source code) in a Bash script? ...

Complete password field scp command on linux

Im writing a shell script to use the scp command (ssh) to transfer a file across to a computer. This obviously is password protected is there a way on either end to either...disable the password or to auto complete the password for the customer? This out of pure convience and I have no idea if it is possible (im fairly new to linux), a...

How to use awk to extract a quoted field?

I am using awk '{ printf "%s", $3 }' to extract some field from a space delimited line. Of course I get partial results when the field is quoted with free spaces inside. May any body suggest a solution please? ...

Exchange two folder names in bash

Often I want to exchange two folders like this: $ mv a{,-alt-tmp} $ mv a{-alt,} $ mv a-alt{-tmp,} i.e. the folder "a" becomes "a-alt" and "a-alt" becomes "a". Is there some bash command to accomplish this? There should be a minimal time gap between the two changes. I could do something similar with $ mv a{,-old} && mv a{-new,} but...

Keep a file open forever within a bash script

I need a way to make a process keep a certain file open forever. Here's an example of what I have so far: sleep 1000 > myfile & It works for a thousand seconds, but really don't want to make some complicated sleep/loop statement. This post suggested that cat is the same thing as sleep for infinite. So I tried this: cat > myfile & I...

How to Keep a MySQL Connection Open in Bash

I have a bash script that calls MySQL several times. Instead of having to reconnect to MySQL, is there a way to keep the connection open? Ideally, the connection would close if the script exits early. I'm thinking named pipes would work but they would stay open. Here's a quick pseudo-example of what I hope to find: openMySQL exec...

Setw and setfill equivalent in BASH

Hi, Could you please tell me what the equivalent BASH code for the following C++ snippet would be: std::cout << std::setfill('x') << std::setw(7) << 250; The output is: xxxx250 Thanks for the help! ...

visual selection in bash / cli

Is there a way to make bash use visual selections for text replacement? Standard text input conventions don't work: If you press Shift+Left Arrow, the character to the left should be visually selected If you press Ctrl+Left Arrow, the cursor should move to the beginning of the previous word If you press Shift+Ctrl+Left Arrow, the wo...

What are the commands for using Git Bash in Windows e.g. when in git diff mode?

In Windows, in Git Bash, if I do a git diff I get all the differences flushed to the console with some sort of prompt to control the output buffer. What are the commands I can use in this mode of Git Bash? I don't know where to look for a quick reference. I've worked out that <Enter> will scroll one line, and <Space> will scroll all lin...