How to match pattern in bash?

2011-02-22 Thread Peng Yu
Suppose that I have a variable $x, I want to test if the content of $x match the pattern 'abc*'. If yes, then do something. (The operator == doesn't match patterns, if I understand it correctly.) Is there such a build-in feature in bash? Or I have to rely on some external program such as perl to t

pushd, popd and dirs of different bash processes communicate by an external file

2011-06-09 Thread Peng Yu
Hi, I'm wondering if there is a way that different bash processes share the same stack. One way of doing so is to use a file to save the stack. It is not difficult to implement this function myself, but I'm just wondering if there is any simpler solution or anybody has done it already. Thanks! --

How to match regex in bash? (any character)

2011-09-26 Thread Peng Yu
Hi, I know that I should use =~ to match regex (bash version 4). However, the man page is not very clear. I don't find how to match (matching any single character). For example, the following regex doesn't match txt. Does anybody know how to match any character (should be '.' in perl) in bash

Re: How to match regex in bash? (any character)

2011-09-26 Thread Peng Yu
On Mon, Sep 26, 2011 at 9:49 PM, John Reiser wrote: > Peng Yu wrote: >> I know that I should use =~ to match regex (bash version 4). >> >> However, the man page is not very clear. I don't find how to match >> (matching any single character). For example, the

Re: How to match regex in bash? (any character)

2011-09-27 Thread Peng Yu
On Tue, Sep 27, 2011 at 6:51 PM, Chet Ramey wrote: > On 9/27/11 6:41 PM, Roger wrote: > >> Correct.  After reading the entire Bash Manual page, I didn't see much >> mention >> of documentation resources (of ERE) besides maybe something about egrep from >> Bash's Manual Page or elsewhere on the we

Re: How to match regex in bash? (any character)

2011-09-29 Thread Peng Yu
On Thu, Sep 29, 2011 at 7:22 AM, Greg Wooledge wrote: > On Wed, Sep 28, 2011 at 12:43:01PM -0800, Roger wrote: >> Seems I used 'man regex' as well here.  AKA regex(3).  But I did >> realize this a few weeks ago; the real regex description being 'man 7 regex'. >> The Bash Manual Page denotes only r

Re: How to match regex in bash? (any character)

2011-09-29 Thread Peng Yu
On Thu, Sep 29, 2011 at 10:38 AM, Chet Ramey wrote: > On 9/29/11 9:48 AM, Peng Yu wrote: > >> Therefore, either bash manpage should specify clearly which regex >> manpage it should be in each system (which a bad choice, because there >> can be a large number of syste

Re: How to match regex in bash? (any character)

2011-09-29 Thread Peng Yu
On Thu, Sep 29, 2011 at 11:06 AM, Greg Wooledge wrote: > On Thu, Sep 29, 2011 at 10:59:19AM -0500, Peng Yu wrote: >> We all have discovered that regex(3) is not consistent across all the >> platform. Why you say it is portable? > > The three systems I mentioned earlier t

How to automatically load alias from .bashrc in a bash script?

2011-10-27 Thread Peng Yu
Hi, I want to use some alias in a bash script. But I have to include the following line in the script in order to use the alias defined in ~/.bashrc. Is there a way to automatically load the alias from .bashrc so that I don't have to explicitly include these two lines? shopt -s expand_aliases . ~

Re: How to automatically load alias from .bashrc in a bash script?

2011-10-27 Thread Peng Yu
On Thu, Oct 27, 2011 at 11:43 AM, Greg Wooledge wrote: > On Thu, Oct 27, 2011 at 04:39:23PM +, Stephane CHAZELAS wrote: >> You mean you'd like every bash script you run on your system to >> automatically source your ~/.bashrc. >> >> That sounds like a very unwise thing to do to me,  but that >

bash-completion between do and done

2011-11-04 Thread Peng Yu
Hi, Current, bash doesn't do command completion between do and done (for loop). I'm wondering if this feature can be added. -- Regards, Peng

What is the best to pass an array with specially characters as command line arguments?

2011-11-06 Thread Peng Yu
Hi, Suppose that I have a verbatim string " a b c ( a'b | " in bash, and I want to pass them as 6 command line arguments. I have to the following conversion using quoteverb.sed to pass the 6 arguments correctly to echo, which is a little bit cumbersome. I'm wondering if there is any better way to

Re: What is the best to pass an array with specially characters as command line arguments?

2011-11-06 Thread Peng Yu
Hi Clark, >> > v="  a b c ( a'b | " >> > a=( $v ) >> > echo "${a[@]}" > > There's a @ char here. I see. It's my mistake. But I want to pass the 6 short arguments instead of 1 long argument to echo. (echo is just an example, it can be any command that accepts multiple arguments.) ~$ cat ./main1

Re: What is the best to pass an array with specially characters as command line arguments?

2011-11-07 Thread Peng Yu
Hi Clark, > What do you mean by "1 long argument"? > > [bash-4.2.10] # cat foo.sh > v="  a b c ( a'b | " > set -o noglob > a=( $v ) > set +o noglob > for i in "${a[@]}"; do >     echo "$i" > done > [bash-4.2.10] # bash foo.sh > a > b > c > ( > a'b > | > [bash-4.2.10] # I misunderstood the usage

Re: What is the best to pass an array with specially characters as command line arguments?

2011-11-07 Thread Peng Yu
On Mon, Nov 7, 2011 at 8:29 AM, Dennis Williamson wrote: > On Mon, Nov 7, 2011 at 7:23 AM, Peng Yu wrote: >> Hi Clark, >> >>> What do you mean by "1 long argument"? >>> >>> [bash-4.2.10] # cat foo.sh >>> v="  a b c ( a'b

What is the correct way to set up login environment in crontab?

2011-11-08 Thread Peng Yu
Hi, I need to use cron to run some job. I know that cron only set up very basic environment. I'd like to duplicate my login environment. But some environment variables are still not seen when I set the following crontab entry. Does anybody know how to correctly set up the login enviroment? (The ma

Re: What is the correct way to set up login environment in crontab?

2011-11-09 Thread Peng Yu
On Wed, Nov 9, 2011 at 7:45 AM, Greg Wooledge wrote: > On Tue, Nov 08, 2011 at 09:46:37PM -0600, Peng Yu wrote: >> I need to use cron to run some job. I know that cron only set up very >> basic environment. I'd like to duplicate my login environment. > > Just so

Re: What is the correct way to set up login environment in crontab?

2011-11-09 Thread Peng Yu
On Wed, Nov 9, 2011 at 7:45 AM, Greg Wooledge wrote: > On Tue, Nov 08, 2011 at 09:46:37PM -0600, Peng Yu wrote: >> I need to use cron to run some job. I know that cron only set up very >> basic environment. I'd like to duplicate my login environment. > > Just so

Re: What is the correct way to set up login environment in crontab?

2011-11-09 Thread Peng Yu
On Wed, Nov 9, 2011 at 10:41 AM, Greg Wooledge wrote: > On Wed, Nov 09, 2011 at 10:29:52AM -0600, Peng Yu wrote: >> I sourced my ~/.bashrc, which source some other files. It seems the >> environment variables defined in these files are not seen with env. >> Why is so? > &

Customize the command resolution in bash?

2011-11-11 Thread Peng Yu
Hi, bash by default searchs in paths specified in the environment variable PATH (separated by ":"). I'm not aware if there is any cache mechanism to save the run time (but even so, different terminals still can not see the same cache, hence each terminal has the overhead to create the cache). When

invoke tilde expansion on quoted string

2011-11-11 Thread Peng Yu
Hi, I know from the document that tilde expansion only works if the string is unquoted (see below) ~$ cd '~/..' -bash: cd: ~/..: No such file or directory ~$ cd ~/.. /Users$ I'm wondering if I already have a string variable, is there a bash native to do tilde expansion on it. var='~/..' cd $var

Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Peng Yu
Hi, It is strange to me why complete doesn't print anything when it is called in a bash script. I must have misunderstood some fundamentals. Does anybody know why? Thanks! ~$ cat main.sh #!/usr/bin/env bash . ~/.bashrc complete ~$ ./main.sh ~$ complete |head complete -F _kill kill complete -F

Re: Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Peng Yu
On Sat, Nov 12, 2011 at 10:01 AM, Andreas Schwab wrote: > Peng Yu writes: > >> It is strange to me why complete doesn't print anything when it is >> called in a bash script. I must have misunderstood some fundamentals. >> Does anybody know why? Thanks! > >

Re: Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Peng Yu
On Sat, Nov 12, 2011 at 10:18 AM, Chet Ramey wrote: > On 11/12/11 10:41 AM, Peng Yu wrote: >> Hi, >> >> It is strange to me why complete doesn't print anything when it is >> called in a bash script. I must have misunderstood some fundamentals. >> Does anybod

converting array to string by quoting each element for eval

2011-11-15 Thread Peng Yu
Hi, I find that I have to make a program quotearg.sh to convert an array to a string by quoting each element. So that it be used for eval. I'm not sure if there is a way that I can do eval in bash without having to use quotearg.sh. If there is no such a way, should quotearg.sh be added in bash (i

Re: converting array to string by quoting each element for eval

2011-11-15 Thread Peng Yu
>   Why not use the array instead of making it into a single string? > > $cmd "${args[@]}" > >   Why are you using eval or quotearg.sh? It sounds as if you are >   making the process more complicated than it need be. For the examples that I gave, probably it is not necessary. I'm yet to make a co

Re: converting array to string by quoting each element for eval

2011-11-15 Thread Peng Yu
>    In any case, combining a command and its arguments in a single >    string is almost always the wrong way to go about it. Please compare the two scripts and see if the second one makes more sense. /tmp$ cat not_convert_args_to_string.sh #!/bin/bash options="$2" find $1 $options echo find $1

Re: converting array to string by quoting each element for eval

2011-11-15 Thread Peng Yu
On Tue, Nov 15, 2011 at 6:43 PM, Chris F.A. Johnson wrote: > On Tue, 15 Nov 2011, Peng Yu wrote: > >>>    In any case, combining a command and its arguments in a single >>>    string is almost always the wrong way to go about it. >> >> Please compare the t

Re: converting array to string by quoting each element for eval

2011-11-15 Thread Peng Yu
>  Then why don't you post that? Please take a look and see if you have a better solution than the following code without using quotearg.sh. /tmp/tmp$ ll * c d: total 0 -rw-r--r-- 1 pengy wheel 0 2011-11-15 20:18:11 xx a b: total 0 -rw-r--r-- 1 pengy wheel 0 2011-11-15 20:18:15 yy /tmp/tmp$ ../c

Re: converting array to string by quoting each element for eval

2011-11-16 Thread Peng Yu
Hi Greg, > **NEVER** use getopt(1).  It is broken.  It cannot be made to work > correctly.  Its entire design is flawed. I don't see these warnings in my systems (macports and ubuntu) (This is version of getopt on macports and ubuntu is free, I don't see there is a reason that getopt can not be p

Re: converting array to string by quoting each element for eval

2011-11-16 Thread Peng Yu
> And that is enough of this nonsense.  I have cited three official manuals > for you already.  Let's move on. I don't get it. Do you mean both traditional getopt and Debian getopt are broken. To me it seems that Debian getopt is made to address the short coming of transitional getopt. Yet you sti

Re: converting array to string by quoting each element for eval

2011-11-16 Thread Peng Yu
> You may safely use getopts (the builtin).  Never getopt. If my understanding is correct, 'getopts' doesn't support the long format. Hence, it does not satisfy my need and I shall not use it. -- Regards, Peng

How to directly modify $@?

2011-11-20 Thread Peng Yu
Hi, I don't see if there is a way to directly modify $@. I know 'shift'. But I'm wondering if there is any other way to modify $@. ~$ 1=x -bash: 1=x: command not found ~$ @=(a b c) -bash: syntax error near unexpected token `a' -- Regards, Peng

How to protect > and interpret it later on? (w/o using eval)

2011-12-01 Thread Peng Yu
Hi, ~$ cat ../execute.sh #!/usr/bin/env bash echo "$@" "$@" $ ../execute.sh ls >/tmp/tmp.txt $ cat /tmp/tmp.txt #I don't want "ls" be in the file ls main.sh '>' will not work unless eval is used in execute.sh. $ ../execute.sh ls '>' /tmp/tmp.txt ls > /tmp/tmp.txt ls: cannot

Re: How to protect > and interpret it later on? (w/o using eval)

2011-12-02 Thread Peng Yu
> WHAT are you trying to DO? I think that you might completely miss my point. I try to explain it better. Let me know if this time it makes more sense to you. I want to execute any command as if the 'execute.sh' does not present, except that I want to print the command so that I know want the com

Re: How to protect > and interpret it later on? (w/o using eval)

2011-12-03 Thread Peng Yu
> THAT will work.  But why are you writing a script to read a shell command > and then execute it?  There is already a program that reads shell commands This capability will be useful for debugging bash script. For example, I have a set of commands in a bash script, each of them output some thing

Ill positioned 'until' keyword

2011-12-14 Thread Peng Yu
Hi, I looks a little wired why 'until' is the way it is now. According to the manual until is before the do-done block. until test-commands; do consequent-commands; done A common design of until in other language is that it allows the loop body be executed at least once and test the condition at

Re: [Help-bash] How to keep only files match the prefix when do command completion?

2011-12-15 Thread Peng Yu
Hi Greg, > New users do not mess with programmable completion. Given the context, I though that it was clear that "new users" means users new to command completion. If it was not clear, I make it explicit here. -- Regards, Peng

Is the description of set -- missing in man bash or at least difficult to find?

2011-12-22 Thread Peng Yu
Hi, As I mentioned previously, there are shortcomings in man bash. Here, I just point another example. And I hope my suggestion will be addressed. As a reasonable search strategy to search for how to set $@ is to search for '$@' in man bash. The literal word '$@' appears at the following location

Re: Is the description of set -- missing in man bash or at least difficult to find?

2011-12-22 Thread Peng Yu
> Second, just search for the 'set' builtin, near the bottom of the man page. Thank for clarifying the usage of set. I looked closely to the document of set. I just find another problem, it says the following. However, the description of -- way down below. It should be the option be described. A

Re: Is the description of set -- missing in man bash or at least difficult to find?

2011-12-22 Thread Peng Yu
> +1 vote on getting the parameters listed with a leading dollar sign. > The individual single character is difficult to search for but the > combination of "$@" and so forth for the others is a useful search > string.  I have often wanted the manual to include the "$@" > combination instead of jus

Re: Is the description of set -- missing in man bash or at least difficult to find?

2011-12-22 Thread Peng Yu
> There are shortcomings in _the man documentation format_ and one of them > is that it doesn't work (at least for me...) when the documentation is > longer than one screen or thereabouts. I've pretty much come to the > conclusion that any man page that is over a couple of hundred lines is > a wast

Specify completion without name

2012-01-04 Thread Peng Yu
Hi, I want to customize the command completion for completing executables, I want to search in a file (which includes all the executables in PATH) rather than the default PATH variable. But I don't see how to do so, as the following help indicates that it can only configure how to complete the arg

Re: Specify completion without name

2012-01-04 Thread Peng Yu
> empty lines. There is no programmable completion mechanism to complete > on non-empty command names. I'm wondering if it is worthwhile to add such a feature. I have run into the problem that it is very slow to command complete an incomplete command especially when other programs are accessing t

Re: Specify completion without name

2012-01-05 Thread Peng Yu
> Presumably you would also include aliases, shell builtins, and functions > in this file. Yes. I just want to replace executables in PATH by the result from my custom function. I think that aliases, builtins, and functions are all in the memory of bash already, so it doesn't take extra time to se

Re: Specify completion without name

2012-01-05 Thread Peng Yu
> I would envision that such a completion function would assemble its list > of possible completions by using your read-from-a-file mechanism and > augment the list using compgen -a/compgen -b/compgen -A function.  It > would probably also want to handle glob patterns and expand them to > potential

Re: Specify completion without name

2012-01-05 Thread Peng Yu
> The bash man page already has ~70 pages manual. I don't like it to grow to > ~700 pages (like the ABS Guide) with all the working examples you expected. > :) Do you use search at all? :) If you use search, it doesn't really matter if is a 700 page manual. -- Regards, Peng

cd won't change the prompt if the command is typed in the vi editor (vi mode).

2013-05-12 Thread Peng Yu
Hi, I have vi mode set. set -o vi. Then I type v to enter the vi editor. In the vi editor, I type 'cd /tmp'. Then, I get the following screen output. Notice that the prompt does not change immediately after the cd command. Could anybody reproduce this behavior? Thanks. ~$ cd /tmp ~$ echo $PWD /

"echo" does not follow the "getopt" convention

2014-08-19 Thread Peng Yu
uot;-- -n". -- -n~$ http://software.frodo.looijaard.name/getopt/ -- Regards, Peng Yu, Ph.D. Assistant Professor Dept. Electrical and Computer Engineering & TEES-AgriLife Center for Bioinformatics and Genomic Systems Engineering (CBGSE) Texas A&M University Office: 215F WEB Phone: (97

How to change the command completion behavior in bash

2009-11-15 Thread Peng Yu
If I have the following in the command line, ~/.bash when I type , it will become /home/my_user_name/.bash I'm wondering if it is possible to configure bash command completion, so that it will still be '~/.bash'

Re: How to change the command completion behavior in bash

2009-11-17 Thread Peng Yu
On Mon, Nov 16, 2009 at 8:30 AM, Chet Ramey wrote: >> If I have the following in the command line, >> >> ~/.bash >> >> when I type , it will become /home/my_user_name/.bash >> >> I'm wondering if it is possible to configure bash command completion, >> so that it will still be '~/.bash' > > You don

Re: How to change the command completion behavior in bash

2009-11-17 Thread Peng Yu
On Mon, Nov 16, 2009 at 4:50 AM, Henning Garus wrote: > On Sun, Nov 15, 2009 at 08:31:38PM -0600, Peng Yu wrote: >> If I have the following in the command line, >> >> ~/.bash >> >> when I type , it will become /home/my_user_name/.bash >> >> I&#x

Re: How to change the command completion behavior in bash

2009-11-17 Thread Peng Yu
On Tue, Nov 17, 2009 at 1:15 PM, Chet Ramey wrote: > Peng Yu wrote: >> On Mon, Nov 16, 2009 at 8:30 AM, Chet Ramey wrote: >>>> If I have the following in the command line, >>>> >>>> ~/.bash >>>> >>>> when I type , it will beco

What files are source in bash login shell?

2009-11-17 Thread Peng Yu
I make my ~/.bash_profile empty. I still see $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games I checked /etc/profile and /etc/bash.bashrc. But I don't PATH is set in the two files. I'm wondering from which file PATH is set. BTW, my system is ubuntu.

Re: What files are source in bash login shell?

2009-11-17 Thread Peng Yu
On Tue, Nov 17, 2009 at 3:12 PM, Bob Proulx wrote: > Peng Yu wrote: >> I make my ~/.bash_profile empty. I still see >> >> $ echo $PATH >> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games > > What is in your ~/.bashrc file? > >> I

Command completion considering characters after the cursor?

2010-01-18 Thread Peng Yu
Suppose I have 'some.sh' in my command line, and my cursor is at '.' $some.sh Suppose there is only one command that start with 'some', which is 'something.sh'. After I type TAB, I will have 'something.sh.sh' in my command line. $something.sh.sh I'm wondering if there is a way to configure bash

Re: Command completion considering characters after the cursor?

2010-01-23 Thread Peng Yu
On Mon, Jan 18, 2010 at 10:00 AM, Chet Ramey wrote: > On 1/18/10 9:49 AM, Peng Yu wrote: >> Suppose I have 'some.sh' in my command line, and my cursor is at '.' >> >> $some.sh >> >> Suppose there is only one command that start with 'some&#

Argument list too long (how to remove the limit)

2010-01-25 Thread Peng Yu
I got the following message. Is there a way to configure bash such that there is not a limit like this? /bin/bash: Argument list too long

Colored command completion

2010-01-26 Thread Peng Yu
I'm wondering if it is possible to color the files shown by command completion (i.e. after typing ). The color scheme can be of the same as the one used in "ls --color=auto". By this way, it is easier to see what the type of the file is.

Circulate matches in command completion?

2010-02-11 Thread Peng Yu
Suppose I file 'a1.txt' and 'a2.txt' in my current directory. When I type 'cat a' then TAB, it will show me 'a1.txt' and 'a2.txt'. If I type TAB repeatedly, it will always show me the same thing. However, a better response might be 1. complete the command to 'cat a1.txt' at the 2nd TAB, 2. complet

Re: Circulate matches in command completion?

2010-02-11 Thread Peng Yu
On Thu, Feb 11, 2010 at 9:58 AM, Chet Ramey wrote: > On 2/11/10 10:54 AM, Peng Yu wrote: >> Suppose I file 'a1.txt' and 'a2.txt' in my current directory. When I >> type 'cat a' then TAB, it will show me 'a1.txt' and 'a2.txt'. I

Re: Circulate matches in command completion?

2010-02-11 Thread Peng Yu
On Thu, Feb 11, 2010 at 10:36 AM, Chet Ramey wrote: > On 2/11/10 11:05 AM, Peng Yu wrote: >> On Thu, Feb 11, 2010 at 9:58 AM, Chet Ramey wrote: >>> On 2/11/10 10:54 AM, Peng Yu wrote: >>>> Suppose I file 'a1.txt' and 'a2.txt' in my current dir

Re: Circulate matches in command completion?

2010-02-11 Thread Peng Yu
On Fri, Feb 12, 2010 at 1:36 PM, DennisW wrote: > On Feb 11, 11:33 am, Peng Yu wrote: >> On Thu, Feb 11, 2010 at 10:36 AM, Chet Ramey wrote: >> > On 2/11/10 11:05 AM, Peng Yu wrote: >> >> On Thu, Feb 11, 2010 at 9:58 AM, Chet Ramey wrote: >> &g

Is there a special variable for the directory where the script is in?

2010-02-11 Thread Peng Yu
$0 gives the file name of the script. I could use several shell command to get the directory where the script is in. But I'm wondering if there is an easy-to-use variable that refers to the directory where the script is in?

Re: Circulate matches in command completion?

2010-02-12 Thread Peng Yu
On Fri, Feb 12, 2010 at 10:43 AM, Chet Ramey wrote: > On 2/11/10 6:14 PM, Peng Yu wrote: > >> bind 'set show-all-if-ambiguous On' >> bind 'TAB:menu-complete' >> >> I typed the above commands in the command line, but I still don't see >&g

Why tab is not colored?

2010-03-07 Thread Peng Yu
My grep is aliased to "grep --color=auto". I then use grep "", where is a tab character. But the result is not colored. How to make the tabs colored?

How cd to a directory with special characters like environment\<\-?

2010-04-08 Thread Peng Yu
I make the following directory and try to cd to it. But I can't. Could you let me know what is the correct way of doing so? $ mkdir environment\<\- $ cd environmen\<\- -bash: cd: environmen<-: No such file or directory -- Regards, Peng

Re: How cd to a directory with special characters like environment\<\-?

2010-04-08 Thread Peng Yu
On Thu, Apr 8, 2010 at 4:58 PM, Peng Yu wrote: > I make the following directory and try to cd to it. But I can't. Could > you let me know what is the correct way of doing so? > > $ mkdir environment\<\- > $ cd environmen\<\- > -bash: cd: environmen<-: No such file

How to start bash without inheriting any environment variables and user level profiles (such as .bash_profile)?

2010-04-28 Thread Peng Yu
I'm wondering how to start bash without inheriting any environment variables and user level profiles (such as .bash_profile). Would you please let me know what option to use? -- Regards, Peng

How to control the width of a number?

2010-05-04 Thread Peng Yu
Hi, I want $page has three digits. If it is less than 100, prefix it with 0. Is there an easy way to do so in bash? for i in `seq 28 55`; do page=`echo '148-('$i'-28)*2'|bc` echo $i $page done -- Regards, Peng

Re: How to control the width of a number?

2010-05-04 Thread Peng Yu
rnal calls to bc and seq in addition to zero-padding > $page. It is good to know this trick. > On Tue, May 4, 2010 at 8:05 AM, Peng Yu wrote: >> Hi, >> >> I want $page has three digits. If it is less than 100, prefix it with >> 0. Is there an easy way to do so in b

How to overwrite a symbolic link?

2010-05-06 Thread Peng Yu
Suppose that I have a symbolic link link1 pointing to file1. When I write to link1, I don't want file1 change. I want it to remove the link generated a new file and write to it. pipe '>' will change file 1. I'm wondering if there is way to do so, so that I don't have to test whether it is a symbol

Re: How to overwrite a symbolic link?

2010-05-06 Thread Peng Yu
On Thu, May 6, 2010 at 10:53 AM, Pierre Gaston wrote: > On Thu, May 6, 2010 at 5:53 PM, Peng Yu wrote: >> Suppose that I have a symbolic link link1 pointing to file1. When I >> write to link1, I don't want file1 change. I want it to remove the >> link generated

Re: How to overwrite a symbolic link?

2010-05-07 Thread Peng Yu
On Thu, May 6, 2010 at 5:36 PM, Bob Proulx wrote: > Peng Yu wrote: >> Is there a way to overload operators like '>' and '>>' in bash, just >> as overloading in C++, etc. Suppose I have already made some bash >> program using '>' and

Re: How to overwrite a symbolic link?

2010-05-07 Thread Peng Yu
On Fri, May 7, 2010 at 9:26 AM, Marc Herbert wrote: > Le 06/05/2010 15:53, Peng Yu a écrit : >> Suppose that I have a symbolic link link1 pointing to file1. When I >> write to link1, I don't want file1 change. I want it to remove the >> link generated a new file and

Re: How to overwrite a symbolic link?

2010-05-07 Thread Peng Yu
On Fri, May 7, 2010 at 10:16 AM, Eric Blake wrote: > On 05/07/2010 09:02 AM, Peng Yu wrote: >> Suppose I need to modify one primary file slightly to do something a >> little bit different. But I still need to do the original job, >> therefore I need to keep it the original M

Re: How to overwrite a symbolic link?

2010-05-09 Thread Peng Yu
On Fri, May 7, 2010 at 10:41 AM, Eric Blake wrote: > On 05/07/2010 09:31 AM, Peng Yu wrote: >> On Fri, May 7, 2010 at 10:16 AM, Eric Blake wrote: >>> On 05/07/2010 09:02 AM, Peng Yu wrote: >>>> Suppose I need to modify one primary file slightly to do something a &g

Re: How to overwrite a symbolic link?

2010-05-10 Thread Peng Yu
On Mon, May 10, 2010 at 6:59 AM, Marc Herbert wrote: > Le 07/05/2010 16:02, Peng Yu a écrit : >> I can copy the whole >> directory and then modify one file in the newly copied N files. But >> I'll lose track of which file has been changed later on, which is >> i

How to use variable in a range like {a..b}?

2010-05-12 Thread Peng Yu
x=10 for i in {1..$x}; do echo $i; done The above code give me {1..10} , rather than printing numbers from 1 to 10. I'm wondering how to use variable in a range? -- Regards, Peng

How to make a directory name with '/' in it?

2010-05-16 Thread Peng Yu
I tried the following command to create a dir with '/' in the name. But it only create a directory with name 'm'. Is there a way to make a directory with '/' in the name? mkdir m\/\/ -- Regards, Peng

How to autocomplete after 'which'?

2010-05-21 Thread Peng Yu
When I type something after 'which', something means a command. However, bash doesn't do command completion for the argument after 'which'. Is there a way to configure bash behave depending on the context (in this case, do autocomplete after 'which')? -- Regards, Peng

Re: How to autocomplete after 'which'?

2010-05-21 Thread Peng Yu
On Fri, May 21, 2010 at 10:39 AM, Chet Ramey wrote: > On 5/21/10 11:25 AM, Peng Yu wrote: >> When I type something after 'which', something means a command. >> However, bash doesn't do command completion for the argument after >> 'which'. Is there a

Re: How to autocomplete after 'which'?

2010-05-21 Thread Peng Yu
On Fri, May 21, 2010 at 11:19 AM, Marc Herbert wrote: > Le 21/05/2010 16:25, Peng Yu a écrit : >> When I type something after 'which', something means a command. >> However, bash doesn't do command completion for the argument after >> 'which'. Is the

Re: How to autocomplete after 'which'?

2010-05-21 Thread Peng Yu
On Fri, May 21, 2010 at 11:06 AM, Eric Blake wrote: > On 05/21/2010 09:50 AM, Peng Yu wrote: >> complete -c works. I'm not familar with bash-completion package. How >> to customize search path for each command. > > By using appropriate complete invocations for each co

Re: How to autocomplete after 'which'?

2010-05-21 Thread Peng Yu
On Fri, May 21, 2010 at 12:07 PM, Eric Blake wrote: > On 05/21/2010 10:41 AM, Peng Yu wrote: >>> 'help complete' is the easiest way to see the short details; other than >>> that, look for complete under 'SHELL BUILTIN COMMANDS' in the man page. >> &

Re: How to autocomplete after 'which'?

2010-05-21 Thread Peng Yu
> You will need to source the file that contains the functions: > > source /etc/bash_completions > > The installation you did most likely added something like this to your > ~/.bashrc: > > # enable programmable completion features (you don't need to enable > # this, if it's already enabled in /etc/

How only show time of files with ls?

2010-05-22 Thread Peng Yu
ls -go gives me permission and file sizes. But I only want to show time and file names. Would you please let me know what command to use? -- Regards, Peng

How not to expand a environment variable when doing command completion?

2010-05-22 Thread Peng Yu
When I type 'cd $HOME/.', bash will expand the command to 'cd /home/my_user_name/.'. Would you please let me know how to let bash expand the environment variable? -- Regards, Peng

Re: How not to expand a environment variable when doing command completion?

2010-05-24 Thread Peng Yu
On Sat, May 22, 2010 at 3:48 PM, Peng Yu wrote: > When I type 'cd $HOME/.', bash will expand the command to 'cd > /home/my_user_name/.'. Would you please let me know how to let bash > expand the environment variable? I mean 'NOT to let bash ...'. A

Re: How not to expand a environment variable when doing command completion?

2010-05-24 Thread Peng Yu
> I also tried 'python $SOME_VARIABLE/', where $SOME_VARIABLE is > set to a directory. Wired enough, this time $SOME_VARIABLE is not > expanded at all, neither any completion to any files under the > directory $SOME_VARIABLE. I was confused. The above statement is not true. -- Regards, Peng

Re: How not to expand a environment variable when doing command completion?

2010-05-25 Thread Peng Yu
On Tue, May 25, 2010 at 9:18 PM, Chet Ramey wrote: >> When I type 'cd $HOME/.', bash will expand the command to 'cd >> /home/my_user_name/.'. Would you please let me know how to let bash >> expand the environment variable? > > There is no setting to suppress the environment variable expansion.  Ba

process substitution with a give suffix

2010-06-08 Thread Peng Yu
I have a program that only accept argument with a give suffix ./program xxx.suffix If I use process substitution, which gives me /dev/fd/xx, it will not work with the program. Is there a way to make sure a suffix is added to the substitute process file handle in /def/fd/, so that the program can

cd multiple levels up?

2010-06-13 Thread Peng Yu
Hello, I frequently need do cd multiple levels up. For example, cd ../.. cd ../../../../ It would be convenient to type something like "cd 2" or "cd 4". Is there a command for this? -- Regards, Peng

How to convert symbolic links pointing outside to a file?

2010-06-14 Thread Peng Yu
Hi, I only want to convert symbolic links that point outside the directory to be archived to a file. But I still want to keep symbolic links point inside as symbolic links. Is there an option or a walkaround to do so in tar? -- Regards, Peng

How not to inherit any environment variable from parent process?

2010-06-22 Thread Peng Yu
I use bash --noprofile to start a bash session. Since this doesn't source any profile files, I'd think that no environment variable should be set. But I still see environment variables set. Are they inherit from the parent session. Is there a way to start a bash session without using parent environ

The usage of {0..${#parameter}}

2010-06-23 Thread Peng Yu
The commented line in the following bash script is not working. I notice the following description from man bash and I think that it is the reason. But I'm not completely sure. Would you please confirm it for me? Also, I'm wondering where this decision was made. Can't bash be made more powerful by

How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Peng Yu
Hi, According to man bash, I thought that $@ instead of $* can help me pass a string with space as a parameter. But it is not. Would you please show me how to print 'b c' as a single argument in the following code? #!/usr/bin/env bash function f { #for i in $*; for i in $@; do echo $i done }

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Peng Yu
On Wed, Jun 23, 2010 at 5:43 PM, Chris F.A. Johnson wrote: > On Wed, 23 Jun 2010, Peng Yu wrote: > >> Hi, >> >> According to man bash, I thought that $@ instead of $* can help me >> pass a string with space as a parameter. But it is not. Would you >> please sh

Where is the syntax of ${arr...@]:1:2} described?

2010-07-08 Thread Peng Yu
Hi, array=(a b c) echo ${arr...@]:1:2} I'm looking for the document for the above usage. I checked the Arrays section of man bash, but I don't see a description of such usage. I also searched man bash with [0-9]+:[0-9]+. But I still don't find a description. Could anybody let me know where this

Re: Where is the syntax of ${arr...@]:1:2} described?

2010-07-08 Thread Peng Yu
sub\u2010 . On Thu, Jul 8, 2010 at 9:27 PM, Peng Yu wrote: > Hi, > > array=(a b c) > echo ${arr...@]:1:2} > > > I'm looking for the document for the above usage. I checked the Arrays > section of man bash, but I don't see a description of such usage. I > a

  1   2   >