LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-26-2013, 12:14 PM   #1
HeidiJTP
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Rep: Reputation: Disabled
which command replaces executable with output


I am trying to run a program that needs to call several other programs, but the which command at the beginning damages the executables it tries to call.

I get the same issue if I run "which" straight from the command line:

Code:
$ which samtools > ~/samtools-0.1.18/samtools
Doing this erases the samtools executable and replaces it with the which command output (/usr/bin/samtools) in a text file of the same name.

I get this result when running it on VMware Ubuntu 11.10 32 bit and also when running it on Ubuntu 12.10 64 bit. The error occurs with calling "which" on other programs as well, not just the example above.

Any advice?
 
Old 03-26-2013, 12:20 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Sincerely it is not clear what you're trying to do, but the posted command line does exactly what is intended for:
Code:
which samtools > ~/samtools-0.1.18/samtools
it redirects the standard output of the which command to the file ~/samtools-0.1.18/samtools. Anyway, what is the purpose of which?
 
Old 03-26-2013, 12:20 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,956

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Perhaps you shouldn't overwrite the executable... What did you really want to accomplish with this command?
 
Old 03-26-2013, 12:23 PM   #4
HeidiJTP
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Sorry, I should have posted what the original program coded for:

Code:
 which samtools > /dev/null || exit 1
I was trying to run just the which command on my own, just noticed my own error!
Anyways, the above "which" command has the same results though
 
Old 03-26-2013, 12:27 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,956

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
No, that's wrong. Recreate the executable, then repeat the process carefully.
 
Old 03-26-2013, 12:32 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
The command in your first post is doing exactly what you're telling it to do. It redirects the output of "which samtools" into the file "~/samtools-0.1.18/samtools". If that file already exists, then it gets overwritten by whatever is being output by "which samtools". That's what the ">" operator does.

The command in post #4 is simply checking whether "which samtools" exited successfully or with an error, and the output is being redirected to /dev/null since you don't care about it.

These are two very different commands. I'm still not sure what it is you're trying to do here, but from what I can tell the computer is doing exactly what you're telling it to do. In other words, PEBKAC.

If you tell us what you're trying to do, then we can tell you what you're doing wrong.

Last edited by suicidaleggroll; 03-26-2013 at 12:34 PM.
 
Old 03-26-2013, 12:39 PM   #7
HeidiJTP
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Fair enough, I had no doubt that it was user error (that's why I'm on the newbie forum!)

Thanks for the help, think I have it straightened out now
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My output file from gfortran compiler is not executable Zope Programming 1 03-08-2013 09:03 AM
[SOLVED] directing output from an executable program into a specific folder emaritza Linux - Newbie 14 07-19-2012 01:39 PM
executable to run a command every n seconds and display output benq70 Linux - Newbie 1 05-01-2008 07:39 PM
Build scripts say my C compiler cannot make executable output noware Linux - Software 2 06-07-2006 03:15 PM


All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration