Find the answer to your Linux question:
Results 1 to 3 of 3
Hi everyone, I 'm writing a script these days and I need to use the command: string link=*ttp://linux.about.com/library/cmd/blcmdln_string.htm ( I am a newbie so the forum doesn't allow to post ...
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    2

    Question Add a new command in bash

    Hi everyone,

    I 'm writing a script these days and I need to use the command: string

    link=*ttp://linux.about.com/library/cmd/blcmdln_string.htm ( I am a newbie so the forum doesn't allow to post URLs yet )


    The bash, however, answers: command not found...
    I tried: "yum install string", but it didn't work.

    Any suggestions?

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Yes, the link does make string seem like a useful command. However, if you look carefully, you will notice references to tcl in places.

    This identifies it as a tcl command. It is not a command available directly through a shell like bash. The page does not do a good job of making that clear.

    Look at the man pages for bash or expr for some string manipulation features.

    Below is an example of string being used in a tclsh script with an example from the link you posted.

    Best wishes ... cheers, drl
    Code:
    #!/usr/bin/env tclsh
    
    # @(#) tcl2     Demonstrate tclsh feature: "string" command.
    
    set version [ info tclversion ]
    set message " Hello, world from tclsh ($version)"
    puts stdout $message
    
    puts stdout ""
    set v1 [ string first a 0a23456789abcdef 5 ]
    puts stdout [ join [ list " variable v1 is " $v1 ] ]
    
    exit 0
    producing:
    Code:
    % ./tcl2
     Hello, world from tclsh (8.4)
    
     variable v1 is  10
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Jun 2011
    Posts
    2
    Found it!!!

    I needed
    Code:
    string range $mystring 3 end
    where mystring="###123", in order to put 123 in a variable...

    But,
    Code:
    len=`expr length $mystring`
    var=`expr substr $line 4 $len`
    works fine in bash.

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...