0

I am trying to concatenate two variables in a csh script

Here is part of the script

#!/bin/csh -f

set encname = _11111k_1920x1080_x264_5200_quicktime_128.mp4

set lowerisrc = `echo $isrc | tr "[:upper:]" "[:lower:]"`

echo "$lowerisrc$encname"

This outputs:

_11111k_1920x1080_x264_5200_quicktime_128.mp4

The lowerisrc variable should be a value for example "ggttgttgg"

It seems as if the lowerisrc variable is not recognized as a string using the lower function

How do I get the following result as the output?

ggttgttgg_11111k_1920x1080_x264_5200_quicktime_128.mp4
BenMorel
  • 34,448
  • 50
  • 182
  • 322
user1526912
  • 15,818
  • 14
  • 57
  • 92

1 Answers1

1

Double quotes don't nest like that. Change the line that sets lowerisrc to:

set lowerisrc = "`echo $isrc | tr '[:upper:]' '[:lower:]'`"

With your current code, that line:

set lowerisrc = "`echo $isrc | tr "[:upper:]" "[:lower:]"`"

contains 3 double-quoted strings:

"`echo $isrc | tr "
" "
"`"

and the [:upper:] and [:lower:] are probably expanded by the shell as file matching patterns.

UPDATE: And now you've changed the code in your question. I just tried your revised code (with the addition of a line to set the value of $isrc), and it works correctly, which makes the question meaningless.

Here's a complete script that works for me:

#!/bin/csh -f

set isrc = GGttGttGG
set encname = _11111k_1920x1080_x264_5200_quicktime_128.mp4
set lowerisrc = "`echo $isrc | tr '[:upper:]' '[:lower:]'`"
echo "$lowerisrc$encname"

The output is:

ggttgttgg_11111k_1920x1080_x264_5200_quicktime_128.mp4
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • This gives me the same output results. – user1526912 Feb 28 '13 at 19:44
  • I was trying different combinations of the upper lower function. I edited the question with the original values. – user1526912 Feb 28 '13 at 19:46
  • @user1526912: If you change the code in your question, it's very difficult to answer consistently. – Keith Thompson Feb 28 '13 at 19:48
  • I am using Ubuntu on an EC2 instance and not getting the correct ouput. I would find it hard to believe that this may be environment related. – user1526912 Feb 28 '13 at 19:55
  • @user1526912: Copy-and-paste the script in my answer and run it on your system. What output do you get? The script in your question doesn't set a value for `$isrc`; could that be the problem? (If `$isrc` is a shell variable you set outside the script, it won't be visible in side the script.) – Keith Thompson Feb 28 '13 at 20:04
  • Thanks Kieth. I tried the same script on Rackspace Linux instance and it works – user1526912 Feb 28 '13 at 20:07
  • @user1526912: EC2 vs. Rackspace *shouldn't* matter. You said the original problem was on EC2. Have you tried my script on EC2? – Keith Thompson Feb 28 '13 at 20:21
  • What I am saying is that my original script posted works on a Centos box in Rackspace. I am saying that the problem is environmental. – user1526912 Feb 28 '13 at 21:18
  • @user1526912: I still can't tell where the value of `$isrc` is coming from. Can you update your question with a *complete* and *self-contained* script that illustrates the problem, and show us the output you get in both environments? – Keith Thompson Mar 01 '13 at 00:43