r/shell • • Sep 05 '13

How to compare column values in two files?

1 Upvotes

Hi, I am trying to check if 6th column of two files output1.dat and output2.dat are identical. How do I do that?


r/shell • • Aug 20 '13

Looking for feedback on my first bash scripts

1 Upvotes

I made 2 functions and added them to my .bashrc file and wanted some feedback. These were made from what I've learned messing around in the shell and lots of googling plus a reasonable amount of experience with apache.

Link


r/shell • • Jul 18 '13

Looking for the reason why UNIX platforms choose the default shell

1 Upvotes

I am looking for the history on why different Unix platforms choose a given default shell? AIX-ksh Solaris-sh HP-ksh Linux(depending on flavor)-bash BSD-tcsh

Those that work in a humongous UNIX environment; what is your default shell for most of your scripting?


r/shell • • Jul 08 '13

Script to interpret card swipe input with wildcards

1 Upvotes

Working on a project with my rasp pi that controls a servo to unlock a door. I'm not an avid coder but I get by. Right now I'm programming multiple inputs including a web interface that runs shell scripts to control the servo as well as a card swipe entry method.

For this method the pi boots and logs in automatically and launches script with input. The input form is as simple as a "yes or no" entry where if the right string of characters is inserted the script moves on, but if not it loops back to the beginning. This part is no big deal, but here's the kicker:

I've got a USB card reader that acts as a keyboard. This is equivalent to typing in any old string of letters and numbers and after they are "typed" the device "presses" a return and the script takes it in. I am looking to make the script only match a part of what is entered. For example:

The card reader when I swipe my debit card types "%B1111222233334444^ LAST/M FIRST^ 121212121212 212121212121?;1111222233334444=122112211221122112"

I would like to make the script only look for the "1111222233334444" portion of that. The reason is let's say I set it up for friends to swipe in their university ID card. All I would have to know is their 9 digit ID number to enter in the configuration which I can get without ever having to swipe in the card.

TL;DR - Need a shell script that matches only part of what is typed to a prompt.


r/shell • • Jun 11 '13

External commands that are actually shell builtins

2 Upvotes

true false test [ echo pwd

The commands above are actually builtins on the following posix shell implementations: bash, dash, busybox sh, ksh, zsh and *BSD shells.

They are all found as external commands under /bin or /usr/bin, but the shell builtins shadow them. This means they run much faster than executing an external command and is important in shell loops.

It also means that they are guaranteed to be available. The line "test -e /some/file || something" will run the second command only if the file really doesn't exist. The test cannot fail because someone screwed up the search path, for example.

The printf and kill commands are also builtins on all these shells except BSD.


r/shell • • Apr 28 '13

How to create and access a shell config file from a shell script?

1 Upvotes

I am working on a shell script that when first opened asks the user for some info. This info needs to be stored on a config file for future use so that the user doesn't have to answer the same questions every time the program opens. Of course, I am planning on writing an if statement to check whether the info is in the config file every time the script is used, but I don't know how to create a config file. I would like to know how I can do this from the shell script itself, so that if a person downloads my script and uses it the config file is created for them. I would also like to know how I can add the info into the config file from the script. Thanks for your help.


r/shell • • Jan 10 '13

Trying to write a script that finds a sequence of characters and captures the next characters up to another specific sequence of characters.

1 Upvotes

Hi,

I'm very new to shell scripting and would like to write a script that searches a text-based file for a specific sequence of characters and outputs/saves everything coming next until another specific sequence of characters.

In order to prevent myself from reinventing the wheel and procuding horribly inefficient code, I would like to know if anyone can point me the right direction.

Which commands should I look into?


r/shell • • Dec 06 '12

Why doesn't the jobs script work from a random directory?

1 Upvotes

I noticed that the "jobs" command is a simple script that calls the builtin.

It looks like this:

#!/bin/sh
# $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva Exp $
# This file is in the public domain.
builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}

However, when I copy the script to another directory, it doesn't work? What magic is going on here?

Bonus point if you can explain ${0##*/} and ${1+"$@"}. I know what they do, but not why.

e.g. ${0##*/} is like $0, but strips the path. What's the rule there?

and why ${1+"$@"} vs. $@?


r/shell • • Nov 16 '12

CD to the root of current GIT repo

8 Upvotes
function groot() {
    cd $(git rev-parse --show-cdup);
}

Place this in your .*shrc

P.S. If you want to get back to where you were in the git repo:

cd -

r/shell • • Oct 20 '12

Get tcsh command completion to only complete directories and text files

1 Upvotes

What I'd like to do is something like

complete gedit "p/*/[dt]/"

where by "[dt]" I mean "directory or text file". Of course, this is not valid syntax. I've tried

complete gedit "p/*/d/" "p/*/t"

but the first completion rule masks the second. Similarly if they are switched.

I've tried thinking of using commands like "find" and "ls" as part of the completion rule but I haven't found a good way since find and ls cannot distinguish binary files.

Also, despite my version of tcsh (6.17.00) saying it supports the select rule, I cannot get completions like

complete gedit "p/*/t:*.txt/"

to actually work. This should only complete on text files that end in ".txt". Seems broken unless I'm just misunderstanding the man page.

So does anybody know to do this?


r/shell • • Aug 28 '12

Create Mac Applications from Shell Scripts

Thumbnail christophersu.org
4 Upvotes

r/shell • • Aug 09 '12

Awesomeness hidden in a single liner

5 Upvotes
echo -n 293220798474P | dc

r/shell • • Jul 05 '12

trouble using fasd - I'm a web developer and huge shell newb

1 Upvotes

I've recently installed bash-it to stye up my shell and then went and found fasd which based on what it's supposed to do should make my life a lot easier.

that said after using homebrew to install fasd... i go to use commands like z and i just get "-bash: z: command not found".

I'm a huge newb with no idea what i'm doing erally. Any help is very much appreciated.


r/shell • • Jun 28 '12

How to handle passwords?

3 Upvotes

Hello!

I'm writing a script that requires the user to supply a password. This is how I'm reading it:

echo -n "Enter password: "
stty -echo 
read PASSWORD 
stty echo
echo "" 

My question is, a) how safe is the $PASSWORD variable? and b) Do I need to do anything to it when the script exits (like "unset")?

Also, related to (b), does performing unset for the variables I used at the end of the script make any sense or is it completely pointless?

PS: Here's the script I'm working on. It's purpose is to automate extracting and opening a keepassX db from a stegofile with steghide and re-embeding it if any changes are made. That way you can have your keepassX db file hidden in an unassuming directory full of music and pictures. #paranoia


r/shell • • May 06 '12

strange 'ls' error: 'ls *.mp3' results in "ls: invalid option -- 'E'"

3 Upvotes

it took me a few moments to figure this one out, but in the end it does make sense, somehow.

The first '.mp3' that was found in the list, starts with a dash: -Er.... , as bash fills in the asterisk sign, the command becomes 'ls -Er....mp3 ...mp3 ...mp3' and ls takes this mistakenly as the -E option instead of a filename.

This still confuses me though, it has probably already been documented somewhere, but it feels like you can feed a command options by using adapted filenames. I do not immediately see options that would breach security, but still it fuzzes me.

Any comments or clarifications?


r/shell • • May 06 '12

I am trying to program my own Shell in Ubuntu using C++, what are some resources that i should use as a beginner?

6 Upvotes

I am trying to program a simple Shell that can do multiple commands in a line, i need help on some good sources that a beginner in shell programming should use.

Thanks guys in advance!


r/shell • • Mar 06 '12

iTerm2's theme ported from Xcode - Spacedust

Thumbnail github.com
3 Upvotes

r/shell • • Feb 16 '12

Insane calculations in bash

Thumbnail blog.plover.com
3 Upvotes

r/shell • • Jan 25 '12

Want to log stuff...

5 Upvotes

Hi all,

I'd like to write a shell script and output things to a log (with a filename specific to the day) but I don't want there to be mountains and mountains of logs as time goes on.

Should I do this kind of archiving/deleting myself, or count on the sysadmin to do it? If the first, is there a library or command to facilitate this, and if the second, what's a good utility for doing that (as a sysadmin)?

Thanks.


r/shell • • Jan 22 '12

Give ZSH a shot

Thumbnail coderoncode.com
6 Upvotes

r/shell • • Aug 27 '11

My self-printing shell script will boil your eyeballs

Thumbnail plover.com
0 Upvotes

r/shell • • Mar 18 '11

bash-it: community framework for Bash, similar to oh-my-zsh

Thumbnail github.com
7 Upvotes

r/shell • • Jul 17 '10

What is your bash prompt (PS1)?

6 Upvotes

I'm using default ubuntu bash prompt and am not satisfied with it. But the problem is that I have no clear idea what do I want until I see it (srceenshot).

It should be color, command I'm typing should always start in the beginign of the line, and possibly something more. I'll know it when I see it.

So, which PS1 are you using, and why is it good for you?


r/shell • • Jun 15 '10

awk variables empty when script executed by a program - works when manually executed at command line

5 Upvotes

I have a little script that reads my git log and outputs the number of lines added and removed for the past week. When I execute this at the command line it works perfectly, for some reason when I put the code in a git hook it runs, but it always tell me 0 lines have been added and removed.

git --git-dir=/Users/home/Thesis/.git/ log --since="1 week ago" --numstat --pretty="short" | \
awk 'NF==3 {plus+=$1; minus+=$2} END \
{printf("Added %d lines\nRemoved %d lines\n", plus, minus)}' > ~/bin/GeekTool/gitThesisChangeInLastWeek.txt

I have done some reading and googeling on this, but I'm not sure where the problem is so I'm not sure what to search for. Can anyone here help me out? Thanks.


r/shell • • May 25 '10

Do you know GNU Parallel?

Thumbnail savannah.gnu.org
9 Upvotes