Get file name in shell scrip loop: bad substitution


 
Thread Tools Search this Thread
Operating Systems Solaris Get file name in shell scrip loop: bad substitution
# 1  
Old 05-02-2011
Get file name in shell scrip loop: bad substitution

Hi guys. Good day, morning, afternoon or night, depending on where you live.
I have a script shell in which I am looping on files (absolute path) see code section above.
I always have an error: bad substitution.
Smilie
Is it because my variable file is the index of the loop and not a normal string?
Code:
for file in $home/$input/*.txt
do
    echo ${file##*/}.log
done

I specify that I need to loop on the absolute path, as I do not want to go inside the files folder, as I am running the script from a bin folder and want to stay in there.

Thanks for your help.
# 2  
Old 05-02-2011
Is that you looking for ?

Code:
for file in $home/$input/*.txt do     basename $file | sed 's/txt/log/'  done

# 3  
Old 05-02-2011
Hi itkamaraj.
Thanks, it's working well.
I have actually customized it into:

Code:
for file in $home/$input/*.txt do     basename $file | sed 's/.txt//'  done

Actually, I will reuse this base name for generating other logs file containing different extensions (bad.log, discard.log...)

Issue is solved.
Thanks.
# 4  
Old 05-02-2011
Code:
for file in $home/$input/*.txt
do 
  echo ${file%%.*}.log
done

# 5  
Old 05-03-2011
Hi rdcwayx.
Thanks for you answer, my problem was solved.

However, your command does not work as it is still returning the entire path I wanted to get rid:
Code:
/........./filename.log

So first solution suggested was better.
Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bad substitution - ShellCheck says okay

ShellCheck doesn't find any issues with this script. #!/bin/bash # color_meanings: explain meanings of colors used in bash ls eval "$(echo "no:fi:di:ln:pi:so:do:bd:cd:or:mi:su:sg:tw:st:ex" | sed -e 's/:/=/g; s/\;/\n/g')" { IFS=: for i in $LS_COLORS do ... (18 Replies)
Discussion started by: Xubuntu56
18 Replies

2. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

3. Shell Programming and Scripting

Bad substitution

Cant undestand :) why i have an error on line 2.it is working on my other boxes #!/bin/bash ret=$(echo Q | timeout 5 openssl s_client connect "${1`hostname`}:${2-443}" -ssl3 2> /dev/null) if echo "${ret}" | grep -q 'Protocol.*SSLv3'; then if echo "${ret}" | grep -q 'Cipher.*0000'; then ... (7 Replies)
Discussion started by: kenshinhimura
7 Replies

4. Shell Programming and Scripting

Bad substitution error in shell script

I have script data.sh which has following error. Script Name : data.sh #!/bin/sh infile=$1 len=${#infile} echo $len texfile=${infile:0:$len-4} echo $texfile run command ./data.sh acb.xml I get following error message: (5 Replies)
Discussion started by: man4ish
5 Replies

5. Shell Programming and Scripting

Why I get bad bad substitution when using eval?

Why I get bad replace when using eval? $ map0=( "0" "0000" "0") $ i=0 $ eval echo \${map$i} 0000 $ a=`eval echo \${map$i}` !!!error happens!!! bash: ${map$i}: bad substitution How to resolve it ? Thanks! (5 Replies)
Discussion started by: 915086731
5 Replies

6. Shell Programming and Scripting

bad substitution error!

Hi All, I'm building a new shell script but i'm facing a problem with one line which is giving "bad substitution" error. Please assist script lines: #!/bin/sh printf "%s: " "Occurrence DATE (YYYYMMDD)"; read DATE shortdate=${DATE#??} o/p: ./test1: bad substitution This command is... (2 Replies)
Discussion started by: Dendany83
2 Replies

7. UNIX for Dummies Questions & Answers

bad substitution

#!/bin/bash a1=( win 12,01,02,03,04 ) a2=( pre 04,05,06 ) a3=( msn 06,07,08,09 ) Given the above arrays, I want the script to return/echo the following in a loop; win 12,01,02,03,04 pre 04,05,06,07 msn 06,07,08,09 But I can't get it to do as such. I've tried; (2 Replies)
Discussion started by: Muhammad Rahiz
2 Replies

8. Shell Programming and Scripting

how to combine two files into one file using shell scrip

eg. file 1 has: 4 0 8628380 653253 0 0 0 0 0 0 2 0 8626407 655222 0 0 0 0 0 0 4 0 8633729 647892 0 0 0 0 0 0 5 0 8646253 635367 0 0 0 0 0 0 file 2 has: 4798 48717 11554 5408 56487 14359 6010 58415 15220 5541 41044... (2 Replies)
Discussion started by: netbanker
2 Replies

9. Shell Programming and Scripting

Bad substitution errors in shell script

Hello, I was hoping for a second pair of eyes or a little bit of help figuring out what my error is in a script. I did some searching in the forums and didn't find anything so please forgive me if it a similar problem has been discussed before. My script accepts normal user arguments; however,... (2 Replies)
Discussion started by: Jackinthemox
2 Replies

10. Shell Programming and Scripting

Bad Substitution

Need Help... I am getting a bad substitution error on my script on a Solaris Server. However the script has been proven to work on HPUX and Solaris servers... #!/usr/bin/sh # # Set the location of the tzupdater.jar file # JAR=/tmp/tzupdater.jar # <<<<< UPDATE THIS LINE... (3 Replies)
Discussion started by: D_Redd74
3 Replies
Login or Register to Ask a Question