0

I'm writing a bash script to edit a youtube video name and I wrote a sed function for it:

function longSed(){
         ins0=$1
         ins1=$( $ins0 | sed 's/and//g;s/ or//g;s/the//g;s/And//g;s/yet//g;s/the//g;s/so//g;s/ a//g;s/ A//g' )
         return $ins1
}

v2=longSed v1
echo "$v1 --> $v2" 

But I keep receiving a command not found error on the second-to-last line no matter what I do. What am I missing here?

EDIT : This is the entire script:

#!/bin/bash

v0=$(youtube-dl --skip-download --get-title --no-warnings $1 | sed 2d )
v1=$(youtube-dl --skip-download --get-title --no-warnings $1 | sed 2d | tr -dc '[:alnum:]\n\r ' | head -c 64 )

function longSed(){
         ins0=$1
         ins1=$( $ins0 | sed 's/and//g;s/ or//g;s/the//g;s/And//g;s/yet//g;s/the//g;s/so//g;s/ a//g;s/ A//g' )
         return $ins1
}

v2=$(longSed v1)
echo "$v0 --> $v2" 

I probably shouldn't be using sed for an entire wordlist like that, but I don't want a separate wordlist file.

Rich
  • 1,103
  • 1
  • 15
  • 36
  • 1
    try `v2=$(longSed v1)`... see https://mywiki.wooledge.org/CommandSubstitution for details on assigning command output to variable – Sundeep Aug 12 '18 at 15:03
  • Now it's saying that there's an error on line 8: `./NameStrip04.sh: line 8: v1: command not found` and that `ins1=$( $ins0 | sed 's/and//g;s/ or//g;s/the//g;s/And//g;s/yet//g;s/the//g;s/so//g;s/ a//g;s/ A//g' )` is a problem. – Rich Aug 12 '18 at 15:05
  • 4
    `$ins0 | sed ...` means you want to execute contents of `ins0` as a command.. you are passing `v1` as parameter.. hence the error if `v1` is not a valid command.. you probably wanted `ins1=$( echo "$ins0" | sed ...)` ?? – Sundeep Aug 12 '18 at 15:08
  • I haven't fully tried to understand the script you wrote.. see https://stackoverflow.com/tags/bash/info for common issues.. for ex: https://stackoverflow.com/questions/4651437/how-to-set-a-variable-to-the-output-of-a-command-in-bash ... – Sundeep Aug 12 '18 at 15:09
  • 1
    Run your script through shellcheck.net – Ed Morton Aug 12 '18 at 15:31
  • I already did that. – Rich Aug 12 '18 at 15:33
  • Not causing your problem, but the syntax for a `bash` function is either `function longSed {` or `longSed() {`(POSIX). – cdarke Aug 12 '18 at 16:18
  • `function longSed ()` is fine, though redundant. – chepner Aug 12 '18 at 16:54

0 Answers0