Author Topic: How do I get a back tick / back quote?  (Read 4136 times)

Scripter

  • Guest
How do I get a back tick / back quote?
« on: September 21, 2009, 09:27:38 PM »
This sounds ridiculous, but how do I get a back tick or back quote character in vi?

As far as I can see, they are essential when writing shell scripts.
Or is there a work around when writing scripts?

Cheers

Scripter

wicknix

  • Guest
Re: How do I get a back tick / back quote?
« Reply #1 on: September 22, 2009, 01:56:07 AM »
Wish i could help, but i never understood vi/vim. Too complicated to figure out. Are you partial to vi? Why not use a different editor like nano (text based), or midnight commander (text based w/syntax highlighting), or nedit, leafpad, geany etc (x11 based).

Cheers

jimux

  • Guest
Re: How do I get a back tick / back quote?
« Reply #2 on: September 22, 2009, 03:01:09 AM »
Ther character you want is the single quote 4 keys to the right of the spacebar on the Uk keyboard.  Used in pairs vi and shell sort out the backward/forewardness.

Scripter

  • Guest
Re: How do I get a back tick / back quote?
« Reply #3 on: September 22, 2009, 10:27:10 AM »
Thanx gentlemen for your speedy replies;

I'm not that keen on vi, but when writing shell scripts it is convenient not to have to swap screens between editing and testing, everything is done in xterm. (I have had stability issues with nEdit).

I tried using the single quote instead of the back tick, but the text gets treated (predictably) as a string not a command.

Maybe I should rephrase the question:

On my UK keyboard there is no back tick key, how can I get the character into a shell script.

Here is my test script:

Code: [Select]
#!/bin/sh

# test of single quote as backtick

LIST='ls'

echo "Listing files:"
echo $LIST

echo "Iterating through files:"
for FILE in $LIST
do
echo $FILE
done

Cheers

Scripter

Scripter

  • Guest
Re: How do I get a back tick / back quote?
« Reply #4 on: September 22, 2009, 11:43:17 AM »
Thanx jimux, you posted a link to a fantastic shell scripting tutorial (in a different thread) at "tldp.org", where I found alternative syntax ;D

Change the following line:
Code: [Select]
LIST='ls'to:
Code: [Select]
LIST=$(ls)
The original syntax I find easier to read, so if anybody does come across a way of generating a back tick/quote please let me know, but I'm happy I got it working.

Cheers

Scripter

wicknix

  • Guest
Re: How do I get a back tick / back quote?
« Reply #5 on: September 22, 2009, 12:51:56 PM »

I'm not that keen on vi, but when writing shell scripts it is convenient not to have to swap screens between editing and testing, everything is done in xterm. (I have had stability issues with nEdit).


Midnight Commander can do that also. Use ctrl+o to switch from mc/mcedit to terminal and back.

Cheers.

Scripter

  • Guest
Re: How do I get a back tick / back quote?
« Reply #6 on: September 22, 2009, 03:35:30 PM »

Thanks wicknix, I'll have to take a look at mc.

Cheers

Scripter


jimux

  • Guest
Re: How do I get a back tick / back quote?
« Reply #7 on: September 23, 2009, 09:49:40 AM »
Now I see what you wanted it for.  I would advise you to use the newer $() format as shells on some machines no longer support the old format - as you have found, and some shells never did.  I am glad you found an alternative in Mendels tutorial, yes it is an excellent work.

Also consider using temporary files as an alternative to variables.  This is not a major overhead as Linux files are stored in ram and then swept to disk when the buffer fills up.  Then you have a number of options using piping and redirection to do things similar to your example.