Re: shell programming question: help with expr command
On Apr 9, 2011, at 6:31 AM, Dino Vliet wrote: > Hi folks, > I'm having trouble with a little shell script. Can somebody explain me why I > get 3 times "expr: syntax error" in my console after I run this little > script? > > #! /usr/local/bin/bash > # testscript > > var1="trees.J48" #other value will be rules.Jrip, rules.DecisionTable > len=${#var1} > ind=`expr index $var1 s` > pos=`expr $len - $ind` > out=`expr substr $var1 $ind $pos` > > I would expect (and want the following to happen): > > $ind should contain 6 > $pos should contain 3 > $out should contain J48 (other values will have to be Jrip,DecisionTable) > > Can anyone help me with this? This would be a /bin/sh compatible (read: portable) way to accomplish the above: #!/bin/sh # testscript var1="trees.J48" #other value will be rules.Jrip, rules.DecisionTable len=${#var1} ind=`echo "$var1" | awk '{print index($0,"s")+1}'` pos=$(( $len - $ind )) out=`echo "$var1" | awk -vind="$ind" -vpos="$pos" '{print substr($0,ind+1,pos)}'` Though, there are certainly easier ways to get at what it is that I assume your after: #!/bin/sh # testscript var1="trees.J48" #other value will be rules.Jrip, rules.DecisionTable out="${var1##*.}" -- Devin > > Thanks > > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" _ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. _ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: shell programming question: help with expr command
On Sat, 9 Apr 2011 06:31:28 -0700 (PDT), Dino Vliet wrote: > Hi folks, > I'm having trouble with a little shell script. Can somebody > explain me why I get 3 times "expr: syntax error" in my > console after I run this little script? > > #! /usr/local/bin/bash > # testscript > > var1="trees.J48" #other value will be rules.Jrip, rules.DecisionTable > len=${#var1} > ind=`expr index $var1 s` > pos=`expr $len - $ind` > out=`expr substr $var1 $ind $pos` > > I would expect (and want the following to happen): > > $ind should contain 6 > $pos should contain 3 > $out should contain J48 (other values will have to be Jrip,DecisionTable) > > Can anyone help me with this? The explaination is quite simple: expr doesn't know "index" or "substr"; see "man expr" for details. A polite sidenote: Unless you have a good reason to code in bash-specific manner, do NOT #!/usr/local/bin/bash, as this is NOT portable (if this is one of your goals); use the standard #!/bin/sh instead. Depending on what you have in mind, maybe mentioning the strengths of perl, sed and awk is worth being mentioned. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
RE: shell programming
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Bill Banks > Sent: 14 November 2007 17:25 > To: FreeBSD Questions > Subject: Re: shell programming > > What am I doing wrough here: > > #!/bin/sh > $DAYN='/bin/date +%a' + "_master.sql" > mysqldump master > $DAYN Your quotes should be backticks not single quotes. Also drop the $ from before the variable name when assigning. #!/bin/sh DAYN=`/bin/date +%a` DAYN="${DAYN}_master.sql" - barry ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
thanks Bill Moran wrote: In response to Bill Banks <[EMAIL PROTECTED]>: What am I doing wrough here: #!/bin/sh $DAYN='/bin/date +%a' + "_master.sql" mysqldump master > $DAYN Those look to be single quotes and not backquotes. (backquote is the upper left key on most keyboards) Wojciech Puchar wrote: dayoftheweek=`date +%w` On Fri, 9 Nov 2007, Bill Banks wrote: I'm writing a backup script. I need to get the day of the week into a variable. How can I do it? -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
In response to Bill Banks <[EMAIL PROTECTED]>: > What am I doing wrough here: > > #!/bin/sh > $DAYN='/bin/date +%a' + "_master.sql" > mysqldump master > $DAYN Those look to be single quotes and not backquotes. (backquote is the upper left key on most keyboards) > > Wojciech Puchar wrote: > > dayoftheweek=`date +%w` > > > > > > > > On Fri, 9 Nov 2007, Bill Banks wrote: > > > >> I'm writing a backup script. I need to get the day of the week into > >> a variable. How can I do it? > >> > >> -- > >> --- > >> Bill Banks 508-829-2005 > >> Wachusett Programming Ourweb > >> http://www.ourweb.net > >> http://www.ourwebtemplates.com > >> > >> > >> ___ > >> freebsd-questions@freebsd.org mailing list > >> http://lists.freebsd.org/mailman/listinfo/freebsd-questions > >> To unsubscribe, send any mail to > >> "[EMAIL PROTECTED]" > >> > >> > > > > > > -- > --- > Bill Banks 508-829-2005 > Wachusett Programming Ourweb > http://www.ourweb.net > http://www.ourwebtemplates.com > > > > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- Bill Moran http://www.potentialtech.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
What am I doing wrough here: #!/bin/sh $DAYN='/bin/date +%a' + "_master.sql" mysqldump master > $DAYN Wojciech Puchar wrote: dayoftheweek=`date +%w` On Fri, 9 Nov 2007, Bill Banks wrote: I'm writing a backup script. I need to get the day of the week into a variable. How can I do it? -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
On Friday 09 November 2007 20:02, Eric Crist wrote: > On Nov 9, 2007, at 11:46 AM, Bill Banks wrote: > > I'm writing a backup script. I need to get the day of the week into > > a variable. How can I do it? > > Well, it depends on what you're using. If you're using sh, see `man > date`. If you're using perl, it's quite complicated. Not really: use POSIX 'strftime'; my $day_of_week = strftime '%A', localtime; POSIX has always been a core module. To see this in action from a commandline, perl -MPOSIX=strftime -le 'print strftime q/%A/, localtime' Jonathan ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
thanks Eric Crist wrote: On Nov 9, 2007, at 11:46 AM, Bill Banks wrote: I'm writing a backup script. I need to get the day of the week into a variable. How can I do it? Well, it depends on what you're using. If you're using sh, see `man date`. If you're using perl, it's quite complicated. In short, with sh, simply use the built-in date command: #!/bin/sh weekday=`date "+%A" See also man 3 strftime - Eric F Crist Secure Computing Networks ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
At 11:46 AM 11/9/2007, Bill Banks wrote: I'm writing a backup script. I need to get the day of the week into a variable. How can I do it? I do this in ksh, but it should work in sh too: DATE=/bin/date TODAY=`$DATE +%m-%d-%Y` TIME=`$DATE +%H:%M:%S` echo Backups started $TODAY at $TIME -Derek -- --- Bill Banks 508-829-2005 Wachusett Programming Ourweb http://www.ourweb.net http://www.ourwebtemplates.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]" -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks transtec Computers for their support. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming
On Nov 9, 2007, at 11:46 AM, Bill Banks wrote: I'm writing a backup script. I need to get the day of the week into a variable. How can I do it? Well, it depends on what you're using. If you're using sh, see `man date`. If you're using perl, it's quite complicated. In short, with sh, simply use the built-in date command: #!/bin/sh weekday=`date "+%A" See also man 3 strftime - Eric F Crist Secure Computing Networks ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
Resolved: After a bit more work and lots of good suggestions, I came up with xterm -e bash --rcfile .myrcfile -i -c "./ticktock && exec bash" & It does everything I was expecting (assuming your regular .bashrc doesn't trash the things you set up in the first environment!) Thanks, all! -- Don Wilde -> Silver Lynx <-- Raising the Trajectory of Human Development - http://www.Silver-Lynx.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Fri, 26 Nov 2004 13:57:31 +0200, Giorgos Keramidas <[EMAIL PROTECTED]> wrote: > On 2004-11-25 17:30, "Conrad J. Sabatier" <[EMAIL PROTECTED]> wrote: > > > > OK, I think I've found what you're looking for: > > > > xterm -e "/usr/local/bin/bash --rcfile bash_commands -i" > > > > Substitute your program's startup script for "bash_commands" in the > > above. Using the "-i" switch to bash forces interactive mode, so > > when the script exits, you'll be returned to the shell prompt in the > > xterm. As it turns out, xterm's "-hold" switch is wholly unnecessary > > here. > > > > Note that the "--rcfile" switch, being a "double-hyphened" option, > > must precede the later "-i" switch in order to be recognized. > > Cool trick! Thanks. :-) > I was thinking something like adding the following to the local > .bashrc: > > [-- .bashrc --] > > if [ ! X"${BASHRC_LOCAL}" = X"" ] && \ > [ -r "${BASHRC_LOCAL}" ]; then > . "${BASHRC_LOCAL}" > fi > > Then running xterm with BASHRC_LOCAL set to the path of the local bash > script: > > BASHRC_LOCAL="/path/foo" xterm -e bash > > --rcfile is better though :-) Yes, it's much simpler, for sure. :-) By the way, there are some better testing constructs that eliminate the need for using the old sh trick of "X$SOMEVAR" to avoid syntax errors. The above expression could be written as: if [ -n ${BASHRC_LOCAL} -a -r ${BASHRC_LOCAL} ]; then ... Or using opposite logic: if [ ! -z ${BASHRC_LOCAL} ... Unix shells are just so damn cool, aren't they? :-) -- Conrad J. Sabatier <[EMAIL PROTECTED]> -- "In Unix veritas" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Fri, Nov 26, 2004 at 09:15:11AM -0700, Don Wilde wrote: > > > > >If you have the option to modify it, ensure that your script exits via > >"exec sh". Alternatively a wrapper that does this is straightforward to > >build. > > > It's looking more and more that I need to make a temporary file that > packages both the init file and the program command line (eval > "blah...") before running. These will not be just shell scripts, they > will be tool programs and x applications. Didn't want to do that because > of the risk of leaving junk in /tmp. It's really socially-acceptable to leave junk in /tmp. /tmp is a volatile dumping ground with no guarantee of file suvival for any length of time, that may even be cleaned on reboot. I played with this for a while, and I have a suspicion that maybe you could use /dev/fd/3 and start bash with something like --rc-file /dev/fd/3 and not close tha standard input, but it's not possible, or I couldn't quite pull it off. (I suspect the latter.) The only other option I can think of involves a temporary file of sorts, too. You could use a FIFO, and then the contents of the "temporary file" wouldn't be left on the disk, but you'd still have the FIFO to deal with. You may also be trying to do something complex enough that it's just more trouble than it's worth to do it with shell programming. Anyway, good luck. -- Adam Fabian ([EMAIL PROTECTED]) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
If you have the option to modify it, ensure that your script exits via "exec sh". Alternatively a wrapper that does this is straightforward to build. It's looking more and more that I need to make a temporary file that packages both the init file and the program command line (eval "blah...") before running. These will not be just shell scripts, they will be tool programs and x applications. Didn't want to do that because of the risk of leaving junk in /tmp. -- Don Wilde -> Silver Lynx <-- Raising the Trajectory of Human Development - http://www.Silver-Lynx.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On 2004-11-25 17:30, "Conrad J. Sabatier" <[EMAIL PROTECTED]> wrote: > > OK, I think I've found what you're looking for: > > xterm -e "/usr/local/bin/bash --rcfile bash_commands -i" > > Substitute your program's startup script for "bash_commands" in the > above. Using the "-i" switch to bash forces interactive mode, so when > the script exits, you'll be returned to the shell prompt in the xterm. > As it turns out, xterm's "-hold" switch is wholly unnecessary here. > > Note that the "--rcfile" switch, being a "double-hyphened" option, must > precede the later "-i" switch in order to be recognized. Cool trick! I was thinking something like adding the following to the local .bashrc: [-- .bashrc --] if [ ! X"${BASHRC_LOCAL}" = X"" ] && \ [ -r "${BASHRC_LOCAL}" ]; then . "${BASHRC_LOCAL}" fi Then running xterm with BASHRC_LOCAL set to the path of the local bash script: BASHRC_LOCAL="/path/foo" xterm -e bash --rcfile is better though :-) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Thu, 25 Nov 2004, Don Wilde wrote: > J65nko BSD wrote: > > On Thu, 25 Nov 2004 10:26:38 -0700, Don Wilde <[EMAIL PROTECTED]> wrote: > > > > > Hey, folks - > > > > > > I need to find a way to kick off an xterm running BASH and then execute > > > a program within that xterm, but NOT close the new xterm after the > > > program finishes. > > [snip] > > > > > xterm -hold -e sh -c ./ticktock & > > > > "-hold" is explained in the xterm man page ;) > > > Yes and no. I don't get as command prompt back in the new xterm, either with > sh or bash. ALso, the --rcfile arcument does not appear to work in conjunction > with -c. > > This is what the man for hold specifies, but I need the prompt. If you have the option to modify it, ensure that your script exits via "exec sh". Alternatively a wrapper that does this is straightforward to build. -- jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/ Tel +44(0)117 9287864 or +44 (0)117 9287088 http://ioctl.org/jan/ Political talk? / What is said can be unsaid / with good old BS -- ASCII haiku ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
It's possible to generate temporary files in a secure manner; there's probably something in the ports collection to generate good, random file names. I'm not sure I'd go to so much trouble to avoid using a file for --init-file or --rc-file. That aside, you could try using expect to script the bash session. -- Adam Fabian ([EMAIL PROTECTED]) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Thu, 25 Nov 2004 11:59:47 -0600, "Conrad J. Sabatier" <[EMAIL PROTECTED]> wrote: > On Thu, 2004-11-25 at 10:26 -0700, Don Wilde wrote: > > Hey, folks - > > > > I need to find a way to kick off an xterm running BASH and then > > execute a program within that xterm, but NOT close the new xterm > > after the program finishes. Another desirable thing would be to also > > be able to 'source in' a file of shell environment that would affect > > the new window > > and shell. > > > > Here's what I've found out so far: > > > > Assume we have an executable test file 'ticktock': > > > > #!/bin/sh > > for n in 1 2 3 4 5 6 7 8 > > do > >echo "$n MYVAR=$MYVAR" > >sleep 1 > >echo -n "continue? " > >read reply > > done > > # end of ticktock > > > > I want to do something like: > > > > xterm -e bash <(echo ./ticktock) & > > > > When I do this, the program works & interacts, but the xterm dies > > upon completion of ticktock or INT. I also do not seem to be able to > > use the --rcfile switch as a bash option, although I can add > > KEY=VALUE pairs before the xterm launch. > > > > Ideas? Please respond to me directly. > > man xterm. There *is* an option to keep the term open after executing > a program. OK, I think I've found what you're looking for: xterm -e "/usr/local/bin/bash --rcfile bash_commands -i" Substitute your program's startup script for "bash_commands" in the above. Using the "-i" switch to bash forces interactive mode, so when the script exits, you'll be returned to the shell prompt in the xterm. As it turns out, xterm's "-hold" switch is wholly unnecessary here. Note that the "--rcfile" switch, being a "double-hyphened" option, must precede the later "-i" switch in order to be recognized. HTH -- Conrad J. Sabatier <[EMAIL PROTECTED]> -- "In Unix veritas" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
When I do this, the program works & interacts, but the xterm dies upon completion of ticktock or INT. I also do not seem to be able to use the --rcfile switch as a bash option, although I can add KEY=VALUE pairs before the xterm launch. Ideas? Please respond to me directly. man xterm. There *is* an option to keep the term open after executing a program. Yes, as another shared: -hold. Unfortunately, it doesn't return to shell prompt. The program is interactive until the program terminates, but I don't get a prompt back from the underlying shell. -- Don Wilde -> Silver Lynx <-- Raising the Trajectory of Human Development - http://www.Silver-Lynx.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Thu, 2004-11-25 at 10:26 -0700, Don Wilde wrote: > Hey, folks - > > I need to find a way to kick off an xterm running BASH and then execute > a program within that xterm, but NOT close the new xterm after the > program finishes. Another desirable thing would be to also be able to > 'source in' a file of shell environment that would affect the new window > and shell. > > Here's what I've found out so far: > > Assume we have an executable test file 'ticktock': > > #!/bin/sh > for n in 1 2 3 4 5 6 7 8 > do >echo "$n MYVAR=$MYVAR" >sleep 1 >echo -n "continue? " >read reply > done > # end of ticktock > > I want to do something like: > > xterm -e bash <(echo ./ticktock) & > > When I do this, the program works & interacts, but the xterm dies upon > completion of ticktock or INT. I also do not seem to be able to use the > --rcfile switch as a bash option, although I can add KEY=VALUE pairs > before the xterm launch. > > Ideas? Please respond to me directly. man xterm. There *is* an option to keep the term open after executing a program. -- Conrad J. Sabatier -- [EMAIL PROTECTED] -- "In Unix veritas" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
J65nko BSD wrote: On Thu, 25 Nov 2004 10:26:38 -0700, Don Wilde <[EMAIL PROTECTED]> wrote: Hey, folks - I need to find a way to kick off an xterm running BASH and then execute a program within that xterm, but NOT close the new xterm after the program finishes. [snip] xterm -hold -e sh -c ./ticktock & "-hold" is explained in the xterm man page ;) Yes and no. I don't get as command prompt back in the new xterm, either with sh or bash. ALso, the --rcfile arcument does not appear to work in conjunction with -c. This is what the man for hold specifies, but I need the prompt. -- Don Wilde -> Silver Lynx <-- Raising the Trajectory of Human Development - http://www.Silver-Lynx.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
Adam Fabian wrote: On Thu, Nov 25, 2004 at 10:26:38AM -0700, Don Wilde wrote: Hey, folks - I need to find a way to kick off an xterm running BASH and then execute a program within that xterm, but NOT close the new xterm after the program finishes. Another desirable thing would be to also be able to 'source in' a file of shell environment that would affect the new window and shell. bash --rc-file \ file_that_contains_the_environment_i_want_and_the_command_i_want_to_run If you mean that you want the xterm to continue running the same instance of bash. I don't think xterms run without the benefit of a program to emulate a terminal for. That's what I don't want to do. I could cat the rcfile and the command in a temp file, but that runs the risk of leaving junk around in /tmp. I'm actually eval'ing this command from another larger program and passing prog-to-be-run from it's argument string after a -e switch. This is to be generalized; I don't know what prog-to-be-run is going to be. -- Don Wilde -> Silver Lynx <-- Raising the Trajectory of Human Development - http://www.Silver-Lynx.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Thu, Nov 25, 2004 at 10:26:38AM -0700, Don Wilde wrote: > completion of ticktock or INT. I also do not seem to be able to use the > --rcfile switch as a bash option, although I can add KEY=VALUE pairs > before the xterm launch. Oops. Didn't notice this until after I replied, but I did test the --rcfile to see if it would work, and it worked like I expected and you described. For reference, it worked for me under FreeBSD 5.3 with bash 2.05b, which I believe was installed from FreeBSD's binary packages for 5.3 -- Adam Fabian ([EMAIL PROTECTED]) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: shell programming challenge
On Thu, Nov 25, 2004 at 10:26:38AM -0700, Don Wilde wrote: > Hey, folks - > > I need to find a way to kick off an xterm running BASH and then execute > a program within that xterm, but NOT close the new xterm after the > program finishes. Another desirable thing would be to also be able to > 'source in' a file of shell environment that would affect the new window > and shell. bash --rc-file \ file_that_contains_the_environment_i_want_and_the_command_i_want_to_run If you mean that you want the xterm to continue running the same instance of bash. I don't think xterms run without the benefit of a program to emulate a terminal for. -- Adam Fabian ([EMAIL PROTECTED]) ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
RE: shell programming - how to write a script that renames files after their last moddate?
On Tue, 27 May 2003, Vince Hoffman wrote: > > > This is certainly not freeBSD specific and probably I'm annoying > > someone for being off-topic but please be patient and hint me on where > > to find good resources in shell-programming. > > > http://www.shelldorado.com/ > isnt bad. otherwise comp.unix.shell is always worth a look. > > > > > > > I could use some help in writing a script that renames all files in a > > directory tree to the files last modified date, example usage: > > > > > daterename "Img_" *.jpg > > > > the command above will rename all *.jpg files to "Imag_".jpg = #!/bin/tcsh set prefix=$1 shift while ( "$1" != "" ) set ext=`expr "$1" : ".*\(\..*\)"` set newname=$prefix`stat -f "%Sm" -t "%F_%H:%M:%S"` echo moving $1 to $newname$ext mv $1 $newname$.ext shift end === BUGS: I'm not sure "stat" works in 4.x If two [or more] files are created at exactly the same time, the one with the last name --in lexicographic order-- will overwrite the others. Hope it helps. ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"