Sponsored Content
Full Discussion: First Script Syntax Error
Top Forums Shell Programming and Scripting First Script Syntax Error Post 302948303 by D351 on Sunday 28th of June 2015 02:13:00 PM
Old 06-28-2015
Quote:
Originally Posted by RudiC
Some comments on your code snippet:
Code:
files=(ls *.mp3)                # this will define & assign an array: (ls a.mp3 b.mp3 c.mp3 ...). You'd need to use it like an array in the for loop, then. 
                                # you might prefer command substitution: files=$(ls *.mp3)
                                # or let the shell do the work for you: files=*.mp3
for song in $files              # this will expand to the first array element: ls. If you want the .mp3 files as well, use array expansion: ${files[@]} if you don't like above proposals
 echo "${song%%*(.mp3)}"        # Why the * and the parentheses? You want to remove nothing but ".mp3", and once only, so one "%" is sufficient
 touch "${song%%*(.mp3)}"       # "${song%.mp3}" will do the job for you. "%*.mp3"  would erase the entire file name, the parentheses can't be matched
                                # and thus stop the expansion.  
                                # You are right in double quoting the file names which will handle spaces in file names, then.
done

I've been cobbling this together from different tutorials found via duckduckgo, so my usage of parenthesis and multiple symbols is sketchy, but based on your advice, I now have:
Code:
#!/bin/bash
#This will create blank lyric files, as used by mocp, for all mp3s in a directory

files=*.mp3
for song in ${files[*]}
do
 echo "${song%.mp3}"
 touch "${song%.mp3}"
done

which appears to be working perfectly. Thank you so much.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error in a script...

Hi All, I have been fighting with a syntax error for the last 2 days, still haven't got the solution. Could you please help me, your help will be greatly appreciated. In my script I am getting a error in a for loop, its similar to the one as is below. for v_id in v1 v2 v3 v4 do... (8 Replies)
Discussion started by: rajus19
8 Replies

2. Shell Programming and Scripting

syntax error in script !!

./disk_space_util.sh ./disk_space_util.sh: Syntax error at line 24 : `then' is not expected. ================================= cat disk_space_util.sh #!/bin/sh # # Parameter Settings ORA_LOG, ORA_SCRIPT, DBA_EMAIL_LIST -- (Set in .profile) bdf | sed "s/%/ /g" | sed "/Filesystem/d" |... (13 Replies)
Discussion started by: uuser
13 Replies

3. Shell Programming and Scripting

Syntax error in script

I get this error when I try to run my script (BTW, this is a simple script I am supposed to write for my class) $ menuscript menuscript: syntax error at line 89 : `"' unmatched $ Here is the code (Any help is greatly appreciated) (Line numbers included) 1 #!/bin/ksh 2 ... (2 Replies)
Discussion started by: KindHead
2 Replies

4. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

5. Shell Programming and Scripting

Syntax error with a script

Hi I not sure what is wrong with my script... when I try to run it I get the follow error: "remove: syntax error at line 77: `end of file' unexpected" Thanks in advance for any help. ans=y while do while : do echo "Please enter a name that you... (3 Replies)
Discussion started by: simpsonjr
3 Replies

6. Shell Programming and Scripting

Syntax error in script

Hey guys keep having problems with the below script syntax error near unpexpected token '0' exit 0 I have two directorys backups and Usr in the usr i have sub dir's wp,ss,pic which i would like to back up (copy those directorys to the backups directory) with user acknowledgement from command line.... (2 Replies)
Discussion started by: Spartukus
2 Replies

7. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

8. Shell Programming and Scripting

Syntax Error in Script

Hi All, I am new to Unix, I have written the following script in ksh and get a syntax error :wall:. I need some help to figure out the error and reason. The script below uses some variables from an environment file, also it executes a sql file. The sql file is correct and has no problems. I... (1 Reply)
Discussion started by: disshort23
1 Replies

9. UNIX for Dummies Questions & Answers

Syntax Error Script

Hi guys i'd like to show you this code of my script, where i couldn't find this error " #! /bin/bash #copiabin.sh: copia todos los archivos ejecutables a bin if then mkdir $HOME/bin fi # copia de archivos y contador N N=0 for ARCH in * do if # Si el archivo es... (9 Replies)
Discussion started by: Newer
9 Replies

10. UNIX for Beginners Questions & Answers

Syntax error on script

Evening All (or morning for some), Could anyone have a look at the below and advise where i've going wrong with the syntax as i keep getting the below error while trying to run. Any help would be really apprecaited. ./testout: line 13: syntax error near unexpected token `else' ... (4 Replies)
Discussion started by: mutley2202
4 Replies
MP3TAG(1)						      General Commands Manual							 MP3TAG(1)

NAME
mp3tag - view and manipulate ID3v1 tags. SYNOPSIS
mp3tag [ -s song ] [ -a artist ] [ -l album ] [ -y year ] [ -e comment ] [ -k track ] [ -g genre ] [ -r ] file [ file ... ] DESCRIPTION
This manual page briefly documents the mp3tag command. This manual page was written for the Debian GNU/Linux distribution because the orig- inal program does not have one. mp3tag is a program that allows you to both view and manipulate ID3v1 metadata tags. Running the command with just a filename will display the file's current tag. Setting some options will cause the tag to be updated and displayed. OPTIONS
-a artist Set the artist name to artist. Strings over thirty characters are truncated. -e comment Set the comment to comment. Strings over thirty characters are truncated. -g genre Set the genre to genre. This is a single integer with a value of 0 to 254 corresponding to the appropriate Winamp compatible genre (use '-g list' to list all supported genres). -k track Set the track number to track. This is a single integer with a value of 0 to 255. Specifying this field truncates the comment field to twenty-eight characters, as per the ID3v1.1 standard. -l album Set the album name to album. Strings over thirty characters are truncated. -r Merge new tag with any preexisting tag in the file. -s song Set the song name to song. Strings over thirty characters are truncated. -y year Set the year to year. Strings over four characters are truncated. EXAMPLES
Display foo.mp3's current ID3v1 info: mp3tag foo.mp3 Set foo.mp3's artist to 'Bar', and album to 'Baz': mp3tag -a Bar -l Baz foo.mp3 Set foo.mp3's year to 2001, merging it with any tag already present: mp3tag -y 2001 -r foo.mp3 AUTHOR
mp3tag was written by Bram Avontuur <bram@avontuur.org>. This manual page was written by Brian Boucheron <brian@boucheron.org>, for the Debian GNU/Linux distribution (but may be used by others). SEE ALSO
More info on ID3v1 can be found at <http://www.id3.org/id3v1.html>. February 19, 2004 MP3TAG(1)
All times are GMT -4. The time now is 05:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy