shell

strip version from package name using Bash

hi, I'm trying to strip the version out of a package name using only Bash. I have one solution but I don't think that's the best one available, so I'd like to know if there's a better way to do it. by better I mean cleaner, easier to understand. suppose I have the string "my-program-1.0" and I want only "my-program". my current solutio...

Using shell tools to extract part of a file

I've got a text file, and wish to extract every above the !--- comment ---! into a new file, not based line numbers (but checking for the comment), How would I do this? test123 bob ted mouse qwerty !--- comment ---! 123456 098786 ...

Windows shell string operations (changing backslash to slash)

Hi there, I need to write a script that takes the current path (%~dp0), transforms backslashes into forward slashes and passes it further to some command. Due to the environment I'm working in the only option that I have is windows shell (not Powershell where the issue would not a problem). Is it even possible to do that? ...

alias with parameters

If there is any possibility to use the parameters in zsh aliases? Something like this: alias ssh_nokia="ssh root@<ip_parameter>" Usage: ssh_nokia 192.168.1.2 ...

Calling a WPF Application and modify exposed properties?

I have a WPF Keyboard Application, it is developed in such a way that an application could call it and modify its properties to adapt the Keyboard to do what it needs to. Right now I have a file *.Keys.Set which tells the application (on open) to style itself according to that new style. I know this file could be passed as a command line...

How do I rename a process on Linux?

I'm using Python, for what it's worth, but will accept answers in any applicable language. I've tried writing to /proc/$pid/cmdline, but that's a readonly file. I've tried assigning a new string to sys.argv[0], but that has no perceptible impact. Are there any other possibilities? My program is executing processes via os.system (equi...

How to run perl script with a few arguments from php

My html webpage calls a php script to upload files to the server from a local computer as follows. <form enctype="multipart/form-data" action="upload.php" method="POST"> <p><b><h3> <font color="#003366"> (1) Upload your reading text file. </font> </h3> </b> </p> <INPUT type="file" name="uploaded" size="50" > <br/> <input type="submi...

Is it bad practice to use python's getattr extensively?

I'm creating a shell-like environment. My original method of handleing user input was to use a dictionary mapping commands (strings) to methods of various classes, making use of the fact that functions are first class objects in python. For flexibility's sake (mostly for parsing commands), I'm thinking of changing my setup such that I'm...

Undesired shortcut shown in the Recent Opened Programs in start menu on Windows 7

Hello all, My software has two .EXE files : A.exe and B.exe. After installed on Window 7, the shortcut to A.exe is always shown in the start menu. (I don't know if 'Start menu' is the correct name or not, what I mean is the area above 'All Programs'). The menu in my computer looks like: Getting Started Windows Media Center Calculat...

sh shell code - retrieving command result.

How can I write a simple shell script that will check if someone using display :0? This does not work: if [ 'who | grep " :0 "' != "" ] then echo "hi" fi ...

I have a very long and repetitive python path, where do I look to correct this?

I know it is probably not necessary to paste the whole path, but just for the record I have done so below. Whenever I run a python command, it takes a long time to load this path I suppose. I have checked in .bash_profile and only have these two lines: export PATH=/Users/username/bin:/opt/local/Library/Frameworks/Python.framework/Versio...

Folder Renaming After Tar Extraction

I have an tarball, myarchive.tar.gz. When I uncompress it using "tar -zxvf myarchive.tar.gz", it creates a folder myarchive-x980-2303-ssioo. What's the easiest way to automatically rename the extracted folder to ensure it matches the name of the archive? I've checked tar's manpage, but it doesn't seem to have an option for this. ...

How to maipulate the shell output in php

I am trying to write php script which does some shell functions like reporting. So i am starting with diskusage report I want in following format drive path ------------total-size --------free-space Nothing else My script is $output = shell_exec('df -h -T'); echo "<pre>$output</pre>"; and its ouput is like below Filesystem T...

./configure : /bin/sh^M : bad interpreter

Hello there, I've been trying to install lpng142 on my fed 12 system. Seems like a problem to me. I get this error [root@localhost lpng142]# ./configure bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory [root@localhost lpng142]# How do I fix this? and for more details, I shall include the /etc/fstub file deta...

Bash script to (more or less) reliably check if the internet is up

I need a bash (or a plain shell) script to put in a cron job that every minute checks if the internet is up. This is how I did it: #! /bin/sh host1=google.com host2=wikipedia.org curr_date=`date +"%Y%m%d%H%M"` echo -n "${curr_date};" ((ping -w5 -c3 $host1 || ping -w5 -c3 $host2) > /dev/null 2>&1) && echo "up" || (echo "down" && exit ...

Split string by newline and space in Bourne shell

I'm currently using the following to split a file into words - Is there some quicker way? while read -r line do for word in $line do words="${words}\n${word}" done done ...

How to remove adornments like [exec] when using groovy's AntBuilder

Hi! I'm using Groovy's AntBuilder to execute Ant tasks: def ant = new AntBuilder() ant.sequential { ant.exec(executable: "cmd", dir: "..", resultproperty: "exec-ret-code") { arg(value: "/c") arg(line: "dir") } } The output lines are prefixed by: [exec] Using Ant on the command line, this is turned off by "em...

How to delete "-" file from svn?

Accidentally I have created file "-" (just a minus) in a directory and commited it. I have to delete it because its causing error on other machines: svn: Can't convert string from 'UTF-8' to native encoding: svn: ?\226?\128?\147 I can remove it from local directory using "rm -i *" or with python "os.remove('\xe2\x80\x93')" but those me...

how do I write a command-line interactive php script?

I want to write a php script that I can use from the command line. I want it to prompt and accept input for a few items, and then spit out some results. I want to do this in php, because all my classes and libraries are in php, and I just want to make a simple command line interface to a few things. The prompting and accepting repeated ...

Calling "other" ImageMagick commands through Imagick?

Hi, I'm using the Imagick PHP wrapper for ImageMagick. I've noticed there are some ImageMagick commands that are not available in the Imagick wrapper, such as autolevel and normalize. How should I go about calling these? Couldn't find anything in Imagick. Are there disadvantages to calling the ImageMagick commands directly through the ...