shell

Python | change text color in shell

I was wondering if anyone knows how to set the color of the text that shows up in the shell. I noticed the 'ls' uses a couple different colors when printing out information to the screen (on my Linux box), was wondering if I could take advantage of that in Python. ...

What are the syntax changes from the shell script to the cshell script?

I just came to know that .sh files don't use set and spaces around = are not allowed, while this is allowed in a .csh file. Is there some place that you can point me to where I can find all these minor differences? ...

Shell commands to match key value pairs

I've got a file that contains a list of key=value pairs, each on its own line. What's the best way to fetch the value for a specified key using shell commands? ...

passing contents to EDITOR and getting the results after quit (e.g. git/svn commit)

I would like to write a command line tool that passes some formatted text to whatever EDITOR the user has set in the environment and then reading the contents back. How do tools like svn commit and git commit handle this behavior? Is there a standard pattern for doing this? ...

Strange variable-argument problem in Capistrano Task

Hello stackoverflow experts, I got a very strange problem in a task I'm creating with Capistrano. I'm trying to pass a variable from the command line: >> cap create_dir -s name_of_dir=mydir task :create_dir do printf("#{name_of_dir}") if !(exists?(:name_of_dir)) then name_of_dir = Capistrano::CLI.ui.ask("Name of dir to be ...

How does Windows associate icons to files in explorer shell?

I have both InDesign CS2 and CS3 installed. Both use files with .indd extension. How does Windows know which icon to use? It uses correct icons i.e. CS2 files have cs2 icon and CS3 files have CS3 icon. How does Windows know how to do this? And how can I extract or use this version-detection system in my programs? Edit: Thank you for ...

Append number to filenames when flattening directory structure on Linux

I have a directory structure that looks like this: /a/f.xml /b/f.xml /c/f.xml /d/f.xml What I want to do is copy all the xml files into one directory like this: /e/f_0.xml /e/f_1.xml /e/f_2.xml /e/f_3.xml How can I do that efficiently on the Linux shell? ...

Can a shell script indicate that its lines be loaded into memory initially?

This is a little thing that bothers me every now and then: I write a shell script (bash) for a quick and dirty job I run the script, and it runs for quite a while While it's running, I edit a few lines in the script, configuring it for a different job But the first process is still reading the same script file and gets all screwed up. ...

shell script to extract mail attachments with specific filename

I'm writing a shell script to extract mail attachments from an mbox file At the moment I use this command: cat mboxfile|formail -des munpack -qf But I'd like to embed the sender email address in the filename, something like: user@host_filename.extension Can you suggest me some tool? ...

How to limit the subset of git commands that zsh will auto-complete (with tab)?

I have a combination of: autoload -Uz compinit compinit and autoload -Uz vcs_info It actually allows for a great amount of integration between git and zsh's tab completion. Too much in fact. How do I limit the set of commands, so that git che(TAB) will expand to checkout, and not to a choice between checkout and checkout-index? ...

Modify sub key in *plist files

I'm would like to modify a subkey in a plist file (i.e. "TB Item Identifiers"): NSNavPanelExpandedStateForSaveMode = 1; NSPreferencesContentSize = "{508, 413}"; NSPreferencesSelectedIndex = 6; "NSToolbar Configuration BrowserWindowToolbarIdentifier" = { "TB Display Mode" = 2; "TB Icon Size Mode" = 1; "TB Is Shown" = 1; ...

How to check file encoding in Linux? Handling multilingual scripts.

Hello Guys, My company has php scripts with texts in different languages (including french, german, spanish, italian and english). Developers decided to use Latin-1 encoding as base for everyone, so this way nobody will override file encoding and corrupt foreign languages in it. (At first some developers used html entities, but this w...

using if elif fi in shell scripts

Hello, I'm not sure how to do an if with multiple tests in shell, I'm having trouble writing this script: echo "You have provided the following arguments $arg1 $arg2 $arg3" if [ "$arg1" = "$arg2" && "$arg1" != "$arg3" ] then echo "Two of the provided args are equal." exit 3 elif [ $arg1 = $arg2 && $arg1 = $arg3 ] then echo "...

Trying to use a grails domain class from the shell

I'm new to Grails. I'm trying to experiement with my grails domains from the shell, and I can't get it to work. These domains work fine from the scaffold code when I run the app. Given this domain class class IncomingCall { String caller_id Date call_time int call_length static constraints = { } } I try to cre...

Efficient way to get your IP address in shell scripts

Context: On *nix systems, one may get the IP address of the machine in a shell script this way: ifconfig | grep 'inet' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' Or this way too: ifconfig | grep 'inet' | grep -v '127.0.0.1' | awk '{print $2}' | sed 's/addr://' Question: Would there be a more straightforward, still porta...

shell float number in expr

I'm trying to get a float number from this : totalmark=$(expr $sum / $subjects ) Is this correct? ...

Shell Extension: DragQueryFile returns at most 16 (in Windows 7)

I've writtten a shell extension (guided by The Complete Idiot's Guide to Writing Shell Extensions) which worked as it should until I upgraded to Windows 7(32bit). Now, the function DragQueryFile UINT uNumFiles = DragQueryFile(hDrop,0xFFFFFFFF,NULL,0); returns the right number of selected files until the number is above 16. Then alw...

Asynchronous shell commands

I honestly can't believe I can't find a solution for this online. I've run across a few things that seem similar, but nothing that really does what I want... I'm trying to use a shell script to start a command. I don't care if/when/how/why it finishes. I want the process to start and run, but I want to be able to get back to my shell im...

Fastest/One-liner way to conditionally remove multiple directories on Unix

What is the shortest way I can write: rm -rfv public/stylesheets public/images public/javascripts and make it conditional, with something like: if [ ! -d public/stylesheets ]; then rm -rfv public/stylesheets; fi ... Just discovered/found a use for command-line conditionals :) ...

Issue with echo and tab in Bash

Hey, I would like to know if its possible to do formatting using echo in shell scripting. Here is a small code snippet which is giving me the problem echo -en "\rFileName : $filename : $index of $lines Completed" The Filename's is a string with varying length and this is causing problem with formating in the terminal. How ...