Find the answer to your Linux question:
Results 1 to 3 of 3
Hi all. I have a fairly simple question, but I can't find the answer anywhere on the internet. All I'm trying to do is get my bash script to rename ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    2

    Output a variable to command

    Hi all. I have a fairly simple question, but I can't find the answer anywhere on the internet. All I'm trying to do is get my bash script to rename some files.

    The command I want the script to run is of the form

    rename 's/4s/2p/' *

    but in place of 4s I want my variable. If I just try something like this

    var=4s
    rename 's/${var}/2p/' *

    I get an error "Global symbol "$var" requires explicit package name at (eval 1) line 1."

    I've tried about a dozen different things now. Obviously the problem is the use of the quotation marks but I just can't work it out. I would be very grateful if someone can show me the correct syntax.

    Thankyou

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    First, try double quotation marks. (")

    If this doesn't work, use xargs.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    2
    Fantastic, works perfectly, thankyou.

    Now I feel incredibly silly for not doing that initially, instead of the incredibly long and convoluted expressions I've been trying for the last half hour.

Posting Permissions

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