LinuxQuestions.org
Visit Jeremy's Blog.
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, 04: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, 04:42 PM   #2
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia 4
Posts: 739

Rep: Reputation: 35
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, 05:04 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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, 05: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, 06:30 PM   #5
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia 4
Posts: 739

Rep: Reputation: 35
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, 07: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, 07: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, 09: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, 03: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, 08:12 AM   #10
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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


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


All times are GMT -5. The time now is 04:19 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