bash

iOS Sync & Backup

Given a jailbroken iPhone and iPad, various windows machines, and a possible shared web host environment, how would I setup the iphone/iPad to automatically sync a folder of files, such that modifying the files or adding on the iPad would result in them being updated/added on the iphone within the file system ( assuming wifi/internet con...

BASH - Read in config file with multiple instances of the same "variable"

I'm trying to read a config file, and then place the "section" of configs into an array in a bash script, and then run a command off that, and then reitterate through the configs again, and continue to do this until the end of the config file. Here's a sample config file: PORT="5000" USER="nobody" PATH="1" OPTIONS="" PORT="5001" US...

remove duplicates per line

I have several csv's that look like this: I have several large text files (csv's) that on some lines have redundant entries. That is, due to the way they were merged a certain field will often have the same value twice or three times. It's not always in the same order though. BWTL, NEWSLETTER, NEWSLETTER BWTL, NEWSLETTER, R2R, NEWSLETT...

[ :Unexpected operator in shell programming

My code: #!/bin/sh #filename:choose.sh read choose [ "$choose" == "y" -o "$choose" == "Y" ] && echo "Yes" && exit 0 [ "$choose" == "n" -o "$choose" == "N" ] && echo "No" && exit 0 echo "Wrong Input" && exit 0 But when I execute sh ./choose.sh terminal prompt me that [: 4: n: :Unexpected operator ...

In Bash, why can we set some environment variable by PS1='something' and others need to be export SOME_VAR='something'?

And why is an export needed? Where is it exporting to? ...

Calling bash functions from sub process

Hi, I'm not sure if its possible, but I'm looking for a way to call a bash function from its subprocess. It could be something like: function testfunc() { echo test function; } bash -c 'testfunc' This doesn't work obviously, but is there any way to achieve something like this? Thanks a lot for the help! ...

string/array operations in bash?

I want to so something like that in bash (.bashrc) so the alias is set based on which comp the user logged in. I don't know how to get the 210 from 10.0.0.210 and then the best way of going through of the list 'user=xxx' $radek ='210' $mike ='209' #SSH_CLIENT='10.0.0.210 53039 22' <--- system variable $user = based on the 4th part of...

Setting bash aliases for IRB ?

So every morning to boot up my server , I need to do the following tasks.. >> sunspot-solr stop >> sunspot-solr start >> script/console >> Organization.reindex >> Event.reindex >> Deal.reindex >> exit >> script/server Is there any way I can make a shortcut in my ~/.profile as an alias to perform all this for me without me typing it ev...

sed, environment variable and date problem

I want to add a timestamp to server events and store the result in a log. My first idea was : ( ./runServer.sh ) | sed "s/.*/`date +%s` & /" | xargs -0 >Server.log 2>&1 & But it seems sed never reevaluates the date, so all events get the same timestamp. Now I'm trying to get around that using environment variable but I can't find ...

bash problem with grep

Whenever i write grep -v "0" in order to ignore the 0 number somehow the number 10 is getting ignored as well. Please help me use the grep -v "0" with ignoring 0 in the process and not ignoring 10 ...

How to tell if user selected "Run In Terminal"

When you double-click a bash script, Ubuntu asks if the user wants to Display, Run, or Run In Terminal... Is there a way within the script to determine if the user chose "Run In Terminal"? ...

How to learn if a value is even or odd in bash?

I am building a movie database and I need to find a median for ratings. I'm really new to bash (it's my first assignment). I wrote: let evencheck=$"(($Amount_of_movies-$Amount_of_0_movies)%2)" if [ $evencheck==0 ] then let median="(($Amount_of_movies-$Amount_of_0_movies)/2)" else let median="(($Amount_of_movies-$Amount_of_0_movies)/2...

Is strftime with nanoseconds possible in bash?

Is there any way to obtain Unix Time with nanoseconds with strftime in bash? My line for unix time : <command> | awk '{ print strftime("%s"), $0; }' I cannot use date +%N because date is only evaluated once. Is there any work around? ...

Bash/Shell Script Function to Verify Git Tag or Commit Exists and Has Been Pushed to Remote Repository

I wanted to get this question out there to see if I'm doing this right. The following script works except for checking to see if the commit has been pushed to a remote repo which I can't find the right command for: #!/bin/bash set -e # fail on first error verify_git_ref() { log "Verifying git tag or commit: \"$1\" ...." ...

Redirect script output to log file OR terminal by request

I'm writing a bash script that I want by default to output everything into a log file. However, I also want the ability to output it to the calling terminal by request (e.g. parameter) INSTEAD of the log file (so tee is out I believe). Does anyone know of a simple way to do this? It would be nice if the parameter could be a custom log...

Change filename by 1 every time (bash script)

I'm making a (bash) script for mass keyfile generation. I need the script to name the first generated keyfile "1", the next "2" and so on - So I need every filename to be the previous filename + 1. The script so far: #!/bin/bash #Files in directory dir=$(ls -U -l /home/user/keyfiles|wc -l) name= #script target=/home/user/keyfiles/$na...

Advanced pgrep-like process search in bash

I need to find the pid of a certain java process in bash on linux. If there's only one java process, PID=$(pgrep java) works. For multiple java processes it becomes more complicated. Manually, I run pstree, find the ancestor of the java process that I need first, then find the java process in question. Is it possible to do this in b...

can I run 'su' in the middle of a bash script?

can I change/su user in the middle of a script? if [ "$user" == "" ]; then echo "Enter the table name"; read user fi gunzip * chown postgres * su postgres dropdb $user psql -c "create database $user with encoding 'unicode';" -U dbname template1 psql -d $user -f *.sql ...

In Bash, how to write alias or function for "export GREP_COLOR='1;32'; grep --color" ?

grep doesn't allow setting color by grep --color='1;32' (1 meaning bold, and 32 meaning green). It has to use GREP_COLOR by export GREP_COLOR='1;32' and then use grep --color How do we alias or write a function for grep so that we have 2 versions of grep (say, grep and grepstrong), one for usual green font, and the other one, gr...

Removing Parts of String That Contain Digit With Sed/Perl (one-liner)

I have a data that looks like this: AB208804_1 446 576 AB208804_1orf 0 AB208804_20 446 576 AB208804_20orf 0 I want to convert them into this: AB208804 446 576 AB208804orf 0 AB208804 446 576 AB208804orf 0 just by removing _\digit part in column 1 and 4. Why this line doesn't work: sed 's/_\d+//g' What's the correct way to do it...