LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 05-09-2008, 03:17 PM   #1
AncientPC
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Rep: Reputation: 15
How am I editting and running two different files?


I have a test script in ~/bin/test.

I have an old test script that contains the lines:
#!/bin/bash
echo "test 0"
exit 0

When I type in "which test" it gives me:
/home/user/bin/test

I then type in "vim `which test`" and modify and save a single line:
#!/bin/bash
echo "test 1"
exit 0

The command: cat `which test` returns the output:
#!/bin/bash
echo "test 1"
exit 0

When I run test, this is the output:
test 0

The command: ~/./bin/test returns the output:
test 1

Why?!?
 
Old 05-09-2008, 03:42 PM   #2
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Because typing vim which test has created a file called which test presumably. Why did you type "vim which test" and not just "vim test"? The only problem with that theory is that you seem to infer typing "vim which test" brought up a file you could modify.

I just don't understand "vim which test".
 
Old 05-09-2008, 04:04 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by DiBosco View Post
Because typing vim which test has created a file called which test presumably. Why did you type "vim which test" and not just "vim test"? The only problem with that theory is that you seem to infer typing "vim which test" brought up a file you could modify.

I just don't understand "vim which test".
Um, note the back-quotes around the which test meaning "the string returned by the the command."

As to the question asked by AncientPC, try a find ~/ | grep test to see if you have other copies of the test script laying around.
 
Old 05-09-2008, 04:09 PM   #4
AncientPC
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 15
"find ~/ | grep test" returns a single file: /home/user/bin/test
 
Old 05-09-2008, 05:30 PM   #5
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Quote:
Originally Posted by PTrenholme View Post
Um, note the back-quotes around the which test meaning "the string returned by the the command."

As to the question asked by AncientPC, try a find ~/ | grep test to see if you have other copies of the test script laying around.
Don't know what a back quote is, but I guess you mean the single inverted commas inside the dual ones. I had tried doing the same thing on scripts I had to see whether I could replicate it, but typing:

vim 'which myscriptname'

or:

vim which myscriptname

just opened up a blank vi session either named which or which myscriptname so I'd assumed the different styles of inverted commas were just for emphasis. Sorry for being thick.

Still don't understand it, what it's supposed to do and why I'm opening up black sessions.
 
Old 05-09-2008, 06:27 PM   #6
fbianconi
Member
 
Registered: Apr 2008
Location: argentina
Distribution: Arch
Posts: 86

Rep: Reputation: 22
Is the file needed to be named 'test' ?
Since it's a very generic name it could be calling different things when you run 'test' on command line, give it a try on 'which -a test' also 'env | grep test' to see if it has been redefined in your environment. Read bash man pages (you're using bash don't you?), I'm sure that has a builtin function named 'test' but I think it doesn't print anything
 
Old 05-09-2008, 06:39 PM   #7
AncientPC
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by DiBosco View Post
Don't know what a back quote is, but I guess you mean the single inverted commas inside the dual ones. I had tried doing the same thing on scripts I had to see whether I could replicate it, but typing:

vim 'which myscriptname'

or:

vim which myscriptname

just opened up a blank vi session either named which or which myscriptname so I'd assumed the different styles of inverted commas were just for emphasis. Sorry for being thick.

Still don't understand it, what it's supposed to do and why I'm opening up black sessions.
A backquote is the quote underneath the ~ key.

It basically evaluates what's between the ` ` before passing it on. For example, I could be redundant and type "ssh `whoami`@server.com" and it would evaluate to "ssh user@server.com" before running it.

Quote:
Originally Posted by fbianconi View Post
Is the file needed to be named 'test' ?
Since it's a very generic name it could be calling different things when you run 'test' on command line, give it a try on 'which -a test' also 'env | grep test' to see if it has been redefined in your environment. Read bash man pages (you're using bash don't you?), I'm sure that has a builtin function named 'test' but I think it doesn't print anything
I've just renamed files for the sake of the forums. In reality, it's called rs-backup.sh and there is not another file that's named the same on the system but the same circumstances / problems apply as above.
 
Old 05-09-2008, 08:25 PM   #8
AncientPC
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 15
I feel retarded and have just found the problem, I've aliased test to something else.
 
Old 05-10-2008, 02:31 AM   #9
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
LOL, nice one, will have to remember that for the next LUG meeting.
 
Old 05-10-2008, 07:12 AM   #10
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Also, remember that test is a BASH "built-in" function, so writing your own executable called test may cause scripts that rely on the test built-in function may produce "unexpected" results.
 
  


Reply



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
Gnome Editting revolutionary_era Ubuntu 4 10-09-2005 07:17 AM
editting .conf files don't take effect eatmars Slackware 6 08-22-2005 12:53 PM
editting rhgb usa1234 Fedora 3 08-28-2004 11:27 AM
Windows cant open files after editting in linux jza Linux - General 2 02-02-2004 05:14 AM
Is there a linux program for creating/editting swf files? mark_alfred Linux - Software 5 12-25-2003 12:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:57 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
Open Source Consulting | Domain Registration