bash

How to delete symbolic links?

I have a script which unzips a whole lot of files under a single directory, some of which are symbolic links. I want to know how to change the script so that, one the unzip has finished, I can get rid of all the symbolic links that were created. ...

Clobber existing file with ar

When using ar with an archive name that already exists, this message is generated: + ar rcs /tmp/libcpfs.a.3nbsv /tmp/cpfs.c.ERGsn /tmp/log.c.1lk6G ar: /tmp/libcpfs.a.3nbsv: File format not recognized The existing archive name is either an empty file (created by mktemp). I want to clobber whatever contents are there anyway, the conte...

Get exit code from a command substitution

In executing the following line in bash: set -e p=$(mktemp -t "${1}.$$.XX") mktemp fails with this message: +++ mktemp -t cpfs.c.o.5643.XX mktemp: too few X's in template `cpfs.c.o.5643.XX' How can I have the error on fail include errors during command substitutions? Alternatively, how can I propagate the return code form mktemp ba...

which short-cut in Zsh does the same as Ctrl-u in Bash?

hi, i know this is probably a silly question. But i googled and searched here, didn't get answer. in Bash, when I was typing a command, i press Ctrl+u, all characters from the beginning of the line to the cursor are gonna be removed. However, in zsh, if I pressed ctrl+u, the whole line is gone. How to do the same in Zsh? Thank you. ...

.profile and .bashrc doesn`t work on my Mac

Hi, This problem I have for a long time. After running terminal .profile, and .bashrc file doesn`t work (are not executed). Could you indicate where should I looking form a source of problem? ...

wxPython -- Bash shell

Hey I want to create a bash-shell in wxPython, the only thing it should be able to do is run a python file and be able to offer user_input on the fly. (I know there is a Python Shell, but that is something different) Can someone help me with this? thanks in advance ...

Guaranteeing every line is received in full from multiple PIPEs (STDOUTs)

Hello, I asked the other day if data integrity (of flushed data) is kept even when there are more than one PIPEs streaming into localhost's STDIN. The answer is NO if the data flushed is large. http://stackoverflow.com/questions/3445047/data-integrity-question-when-collecting-stdouts-from-multiple-remote-hosts-over-s But I would like t...

How to check if today is a weekend in bash?

How to check if today is a weekend using bash or even perl? I want to prevent certain programs to run on a weekend. Thanks ...

Why the sh script cannot work

Hi, I write a sh script (test.sh) like this: #!/bin/sh echo $@ and then run it like this: #./test.sh '["hello"]' but the output is: " In fact I need ["hello"] The bash version is: #bash --version GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu) And if I run # echo '["hello"]' ["hello"] I don't know why th...

substring by char range

10.11.183.81,aaa_XXX150.csv,bbb_YYYY_20100807.csv how can i get string between every , and _ such as aaa bbb ...

Creating a shorter version of a bash command

i am novice to the Linux shell and had to recently start using it for work...i have now got used to the basic commands in bash to find my way around...however there are a lot of commands i find myself typing over and over again and its kind of a hassle to type them every time...so can anyone tell me how can i shorten the command syntax f...

Get the newest file based on timestamp

I am new to shell scripting so i need some help need how to go about with this problem. I have a directory which contains files in the following format. The files are in a diretory called /incoming/external/data AA_20100806.dat AA_20100807.dat AA_20100808.dat AA_20100809.dat AA_20100810.dat AA_20100811.dat AA_20100812.dat As you ca...

Run git pull over all subdirectories

Hi, How can I run git pull origin master on all sub directories of a directory. I.E. I have /plugins/cms /plugins/admin /plugins/chart etc and I want to update them all at the same time. (Im running debian linux) ...

shell scripting 101 question

Given: myvar=Hello echo $myvar -> Shows Hello (fine so far) echo $myvar#world -> shows Hello#world (why?? I thought it would complain that here is no such variable calld myvar#world echo ${myvar#world} -> shows just Hello (again, why??) Thanks in advance ...

Why don't my bash shell scripts execute consistently?

I encountered some weird bahavior on my linux system. I created some bash script files, and changed their mode to be executable. However, some can be called and executed, while others can not (with err msg of command not found). As a result, I had cp a file based on the one which was able to be found and executed, then replaced the newly...

Code challenge: Bash prompt path shortener

I implemented a prompt path shortener for bash to be included in the PS1 environment variable, which shortens the working directory into something more compact but still descriptive. I'm curious what other ideas may exist. Here's the challenge: Create a bash function _dir_chomp which can be included into PS1 like this (line breaks inse...

Bash script to kill and restart Hudson

I am a novice at Bash scripting but I'm a quick learner. Usually. I'm trying to write a script to kill and restart an instance of Hudson--it needs to be restarted to pick up changes in environment variables. What I have so far: #!/bin/bash h=`pgrep -f hudson` if test "$h" != ""; then kill $h while [ "$h" != "" ]; do sleep 1 ...

unix commandline for inline replacement of all newlines in file with <br>\n

sed 's/$/<br>/' mytext.txt worked but output it all on the command line. I want it to just do the replacement WITHIN the specified file itself. Should I be using another tool? ...

What are the most important shell/terminal concepts/commands for novice to learn?

ALthough I've had to dabble in shell scripting and commands, I still consider myself a novice and I'm interested to hear from others what they consider to be crucial bits of knowledge. Here's an example of something that I think is important: I think understanding $PATH is crucial. In order to run psql, for instance, the PostgreSQL fo...

encrypting/decrypting password stored in config file

I have a simple Bash script automating tasks which require password-based authentication. Currently I store the credentials in plain text: $ cat ~/.myconfig username=foo password=bar Obviously that's bad - so I wonder whether there's a simple way to encrypt/decrypt the password using my public/private key pair. Using Yet Another Passw...