The Behaviour Of Single & Double Quotes In Writing & Running Aliases?

This isn't a problem, more a how or a why:

I have always written an alias (alias ln="ln -sv") which changes the instruction for a "hard" link into one for a "soft". This worked fine until I needed a hard link, so, as part of the alias, I decided to give myself a reminder of what I was doing. After a bit of a struggle, I ended up with this (which I stuffed into my .bash_aliases file):

alias ln="echo -e 'Symbolic (soft) Link (use \033[1;36mhln\033[0m for Hard Link)\nuse \033[1;36m-f\033[0m for force'; ln -sv "

and it works:

Symbolic (soft) Link (use hln for Hard Link )
use -f for force
ln: missing file operand
Try 'ln --help' for more information.

(OK, no operand was supplied here, but the stuff we're talking about works fine).

Recently, however, I needed to look at the construction of the alias, ran "alias ln" & got:

alias ln='echo -e '\''Symbolic (soft) Link (use \033[1;36mhln\033[0m for Hard Link)\nuse \033[1;36m-f\033[0m for force'\''; ln -sv'

Now, I can (sort of) understand the logic of what's going on here, but not entirely - viz:

..1...'...............Open 'protected' mode (was double quote)
........echo -e....Command: invoke "echo -e"
..2...'...............matches 1: Closes 'protected' mode
........\.............invoke newline(\)? Or is this simply an scape character? (Yes it is see http://www.linuxquestions.org/questi...-quote-861714/)
..3...'...............Reopen 'protected' mode (or an escaped single quote - if so why?)
..4...'...............0pens 'protected' mode for "message" code
........Symbolic (soft) Link (use \033[1;36mhln\033[0m for Hard
........Link)\nuse \033[1;36m-f\033[0m for force
..5...'...............5 matches 4 (closes message code),
........\.............invoke newline(\) - or see above
..6...'...............6 matches 3 & closes the section started @ 'reopen'
..7...'...............Reopens 'protected' mode
........; ln -sv......New command[ ; ], creates link
..8...'...............8 matches 7 - the end (or is it?)

I would guess that the "alias" command has some built built in function that does all this - I have saved the the modified version as an alias & it works fine - but although I have read the excellent post:

http://www.linuxquestions.org/questi...-quote-861714/

I don't understand why the system has both double & single quotes. I have always felt that as long as the command line was explained & demonstrated in simple language it was easier to work with that than any point & click system. I grew up with CPM, DOS, Qemm, Desqview, WP5.1, DbII and these were great programs with great (especially WP51) manuals - but, ahh! - those days have gone

Any suggestions gratefully received

dmk


Similar Content



Possible To Create Symbolic Link On Live USB For Main System?

Hello all,

I was going through LFS yesterday and planned to change the symbolic link from "{bin/sh}{dash}" to "{bin/sh}{bash}". Unfortunately, I disconnected from bin/sh but forgot to create another link. Now the system won't boot and failed to shutdown. Wondering if I can make a symbolic link for it on the Live USB or is there another solution? The Distro is Linux Mint 17.1.

Thanks.

Problem With .bashrc Entry

I need to execute this .bashrc string:

alias lml='grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' mail.log | grep "relay=" | awk '{print $8}'' #list mail log

I have tried enclosing the string in alias as lml="..." and alias lml=`...` to no avail. The problem is apparently with the grep "relay=" in that it has to be enclosed in "", as well as the awk that has to be enclosed in ''.

Any ideas on how to get this setup? Thanks.

New Problem With Aliases

I have many .bashrc aliases. When I used to type in an alias, it just executed the alias. Now something has changed. When I type in the alias, it prints the alias lines and then executes the commands:

alias cde='cd /etc/ && ls --color -a' #get to /etc

root@me~# cde
cd /etc/
ls --color -a
...into /etc and list of folders/files follows...

How can I stop the

cd /etc/
ls --color -a

from being displayed?

Thanks.

How Do I Know If A File Has A Hard Link To It?

ok I know when I create a soft link, it shows a ----> in a long listing and is colored (if ls --color) in aqua.

But hard links don't do this. How can I tell if a file/dir has a hard link to it or if it points to another file?

How To Patch OSPF In Ns2.34

Hi mates,

I am trying to patch ospf in ns-2.34 i have downloaded the patch file from link:

http://sourceforge.net/projects/ospf...s/ospf4ns2.34/

$ cd ns-allinone-2.34/
$ patch -p0 < 20-ospf4ns2.34-examples.patch

Using : $ cd ns-2.34/
# make install

$ cd tcl/ex/ospf/
$ mkdir out_ospf0 out_ospf1 out_ospf2 out_ospf3 out_ospf4 out_ospf5 out_ospf6 out_ospf7 out_ospf8 out_ospf9
$ ns ospf0.tcl

i followed the procedure from below LQ link post no #3

http://www.linuxquestions.org/questi...-a-4175492253/

it is successfully patchinf file but it is showing error when i execute ospf0.tcl file



Quote:
(TCL) Creating simulator & trace files...
(TCL) Setting up nodes and links...
(TCL) Configuring traffic objects...
(TCL) Configuring routing protocol...
invalid command name "Agent/rtProto/OSPF"
while executing
"Agent/rtProto/OSPF set helloInterval 1"
(file "ospf0.tcl" line 132)



pls anyone suggest me ideas to get rid of this err.

Thanks in Advance,

Pon

Sendmail Alias Not Working

I'm trying to send all root's mails to an external e-mailaddress, but for some reason I can't get it to work.

I've edited /etc/aliases with the following rule:

root: <myexternal@email.address>

and run newaliasses after, which would run without any errors.

I can run: echo "Testing" | mail -s "Server Testing" <myexternal@email.address>
just fine without any issue and it's being delivered correctly to my external address.

But when I run: echo "Testing" | mail -s "Server Testing" root

I (first) get a "Deferred: 451 Temporary local problem - please try again later" error and when I then run: "Sendmail -OTimeout.hoststatus=0m -q -v" to flush the mailqueue it says everything is ok, but I then get a message saying I have new mail in /var/spool/mail/root and I don't get the mail on my external e-mailaddress.

I have no clue where to look next, hopefully you guys can point me in the right direction.

Just for completeness: I use mageia release 4 (x86_x64).

Zenity Radiolist Parameters In Variables

Note: Ubuntu 14 latest release

I am a highly experienced unix user with many years of experience. However, I retired 13 years ago so I can't remember some simple things so forgive me for posting here.

I am trying to use the "zenity --list --radiolist" command. Now this requires that the list of items be last and be of the form FALSE <item name> as in FALSE "Choice 1" FALSE "Choice 2" That's easy without variables. It would be zenity --list --radiolist [other options here] FALSE "Choice 1" FALSE "Choice 2 Works fine.

But what I have is a list of choices in an array. Each of these is a string of multiple words and I have tried (nearly?) everything using echo command piped into zenity (supposed to work) to including an array element in the line with all sorts of quotes, single quotes, escaping quotes, etc. I have even included the "FALSE" in the variable so as not to have to generate it. Nothing works. When using the set -x, it shows that the shell has put a single quote around each word which makes each word a separate parameter.

I have searched all sorts of examples of zenity but the requirement for the word "FALSE" between each item while using variables is never shown.

If anyone has a working example of something like this (or any simple alternative:
JTemp[3]="This is a string"
echo "FALSE "${Jtemp[3]} | zenity --list --radiolist --text "Select Topic" --column "Topic" --column "Pick one" which should display a radiobox with one entry, I would appreciate it. I could then expand it to include all the array elements.

I know I am doing something simple wrong. I just can't figure it out.

Note that I am writing this on a windows machine and using a non-internet-connected linux machine for my work so if I typed the command line wrong, it may be a problem here and not on the real machine.

Thanks for any help.

Kinds Of Links In Linux And Use Of Unlink

Hello, I am learning about file types in Linux, and i see there are hard and symbolic links, also I saw that unlink function in C deletes a link to a file and decrements the intern link counter. The problem is that i don't understand what link is deleted when unlink is called. Is it the parents link to that file?

Misbehaving 'echo' Command On Cygwin

Hi,

I've used unix before, but have just started to play with CYGWIN (1.1.3) on windows XP (32 bit). I'm having trouble getting 'echo' to behave as I would expect.

I've created a script called runstuff which contains these lines....
Code:
#!/bin/bash
# This line works as expected....
echo "the user is <$USER> and the hostname is <$HOSTNAME>"
MYVAR1=bill
MYVAR2=fred
# This lines doesn't.....
echo "my first variable is<$MYVAR1> and my second is <$MYVAR2>"

The output I get is this...
Quote:
$ runstuff
the user is <Mike> and the hostname is <MikesLaptop>
> and my second is <fredl

In the first echo statement it is just echoing a couple of external variables - this works as expected. In the 2nd echo example the two variables are internal, but the displayed output isn't what I'd expect, my guess is that the first part of the output "my first variable is <bill" has somehow been overwritten by the remainder of the string. Or am I missing something?

I have tried exporting the variables, and I've experimented with wrapping them in quotes, but the results are always the same.

Any help gratefully received.

Check Empty Variable Without Comments

Hello,

They gave me this:
Code:
#!/bin/bash

# Write error message on stderr and die
function die() {
  echo "$@" >&2
  exit 1
}

# Load var from properties files
function load() {
  for propertie in "$@" ; do
    [[ -f "${propertie}" ]] || die "load() : \"${propertie}\" don't exist !"
    while read ; do
echo "${REPLY%=*}"
echo "${REPLY#*=}"
      [[ -n "${REPLY%%=*}" && -z "${REPLY#*=}" ]] || die "load() : Variable \"${REPLY%%=*}\" is empty!"
      eval "${REPLY%%=*}"=\'"${REPLY#*=}"\'
    done < "${propertie}"
  done
}

load "manage_srcds.conf"
echo "SRCDS_TICKRATE=$SRCDS_TICKRATE"
echo "SRCDS_SCREEN=$SRCDS_SCREEN"
echo "SRCDS_SRCDS_GAME_NAME=$SRCDS_GAME_NAME"
echo "SRCDS_MAXPLAYERS=$SRCDS_MAXPLAYERS"

but, return:
Quote:
###################################################
###################################################
load() : Variable "###################################################" is empty!

cat manage_srcds.conf

I just wish that there was no empty variable excluding those who do not have integer.

Best regards,