How specify the location of TAGS file? - ctags

I have the following parameters for the ctags:
ctags -f TAGS -e -R --langmap=php:+.inc.foo.bar --list-maps=php
Any idea how I could specify where the TAGS-file should be placed? I found nothing about this in man ctags and ctags --help, only about which filename the TAGS file should have.

The file name after parameter -f can be just a file name without path, but can be also with a relative path or with a full absolute path.
For example on Windows:
ctags -f "C:\My Projects\ProjectX\ProjectX_tags.txt" -e -R --langmap=php:+.inc.foo.bar --list-maps=php
Double quotes are needed only if the path or file name contains 1 or more spaces.

How about something like:
ctags -f - > /path/to/final/dest/tags
so the -f - part redirects the tags file to stdout, then we use shell redirection to send it to the destination of our choice.

Related

how to include path of a directory containing files inside bash script

I am writing a bash script that will get the user defined filenames and then use alsa to play that file:
#!/bin/bash
export PATH=$PATH:/home/pi/Documents/audio
read -p "Enter a filename: " filename
aplay $filename
Above is what I have tried after reading about how to include path in a script. But at the terminal prompt, after I do ./script.sh, it returns no such a file in the directory. I also tried source ./script.sh thinking that the environment is only changed in the subshell and it returns the same.
All I need is to include the path within this script and does not change the system path permanently.
I'd appreciate it if someone can point me to the right direction. Thank you!
PATH is used for finding programs, not data files. If you want $filename to be a file in the audio directory, you need to concatenate it explicitly.
#!/bin/bash
audiodir=/home/pi/Documents/audio
read -r -p "Enter a filename: " filename
aplay "$audiodir/$filename"
Try specifying the absolute path of the file that you're playing like this:
#!/bin/bash
AUDIO_PATH="/home/pi/Documents/audio"
read -p "Enter a filename: " filename
aplay "${AUDIO_PATH}/${filename}"

shell scripting no such file or directory

I wrote a shell script that calls the ffmpeg tool but when I run it, it says No such file or directory yet it does!
Here is my script:
#!/bin/bash
MAIN_DIR="/media/sf_data/pipeline"
FFMPEG_DIR="/media/sf_data/livraison_transcripts/ffmpeg-git-20180208-64bit-static"
for file in MAIN_DIR/audio_mp3/*.mp3;
do
cp -p file FFMPEG_DIR;
done
for file in FFMPEG_DIR/*.mp3;
do
./ffmpeg -i ${file%.mp3}.ogg
sox $file -t raw --channels=1 --bits=16 --rate=16000 --encoding=signed-
integer --endian=little ${file%.ogg}.raw;
done
for file in FFMPEG_DIR/*.raw;
do
cp -p file MAIN_DIR/pipeline/audio_raw/;
done
and here is the debug response:
cp: cannot stat ‘file’: No such file or directory
./essai.sh: line 14: ./ffmpeg: No such file or directory
sox FAIL formats: can't open input file `FFMPEG_DIR/*.mp3': No such file or
directory
cp: cannot stat ‘file’: No such file or directory
FYI I'm running CentOS7 on VirtualBox
Thank you
Here's a Minimal, Complete, and Verifiable example (MCVE), a version of your script that removes everything not required to show the problem:
#!/bin/bash
MAIN_DIR="/media/sf_data/pipeline"
echo MAIN_DIR
Expected output:
/media/sf_data/pipeline
Actual output:
MAIN_DIR
This is because bash requires a $ when expanding variables:
#!/bin/bash
MAIN_DIR="/media/sf_data/pipeline"
echo "$MAIN_DIR"
The quotes are not required to fix the issue, but prevent issues with whitespaces.
Hi You need couple of correction in your shell script see below. To get the actual value assigned to a variable you need to add $ at the front of the variable in shell script.
for file in $"MAIN_DIR"/audio_mp3/*.mp3;
do
cp -p "$file" "$FFMPEG_DIR";
done
for file in "$FFMPEG_DIR"/*.mp3;
./ffmpeg -i ${file%.mp3}.ogg
#provide full path like /usr/bin/ffmpeg
for file in "$FFMPEG_DIR"/*.raw;
do
cp -p "$file" "$MAIN_DIR"/pipeline/audio_raw/;
done

Shell: use of for on a variable list

Unfortunately my shell skills are very bad and I would need some help in running a simple script on my QNAP to fix some date problem on some videos.
The script I put in place is very easy:
in a given folder
check if there are .mp4 files starting with VID_
if so, for each of them run a given exiftool command
Here is the script so far, but I guess I am not using the right way to call the variable:
#!/bin/sh
# set target directories
dir="/share/Multimedia/Pictures/"
# move to target directory
cd "$dir"
# check if there is some .mp4 file starting with "VID_" in the folder
VID=$(ls -A $dir | grep 'VID_' | grep './mp4')
if
["$VID"];
then
# for each file in the list
for f in $VID
do
# change all date metadata according to its filename
exiftool "-*date<filename" -wm w $f
done
else
fi
Thanks for your help!
ps: the exiftool instruction is correct (except probably for the variable)
There isn't a need to script this, doing so just slows you down as you have to call ExifTool for every file. ExifTool can do all the files in one pass:
ExifTool -ext mp4 '-*date<filename' -wm w /path/to/dir/VID_*
The -ext mp4 options limits the command to only mp4 files. Since you seem to be on a linux/mac system, the double quotes had to be changed to single quotes. Double quotes are needed on Windows systems, single quotes on linux/mac systems.
Your code is probably failing due to use of:
grep './mp4'
Since there is no / before mp4.
Better to have your script as:
#!/bin/sh
# set target directories
dir="/share/Multimedia/Pictures/"
# move to target directory
cd "$dir"
for f in VID_*.mp4; do
exiftool "-*date<filename" -wm w "$f"
done
No need to parse output of ls here and there is no need to use grep since glob VID_*.mp4 will do the job of finding correct files.

Error: Tar command not found

echo "Enter path of backup file e.g /tmp/backup/etc.tar.gz : "
read PATH #input was /tmp/backup/etc.tar.gz
echo "Enter directory: "
read DIR #input was /root/testing
sudo tar -zvxf "$PATH" -C "$DIR"
when I ran the script, it said that the command was not found. I tried using whatever kind of brackets for the variables but still not working. Any help?
However when I ran the command tar -zvxf /tmp/backup/etc.tar.gz -C /root/testing , it worked.
You're saving something into PATH which is what the shell will search to find the executables. So when you use that variable the shell can't find, say, tar because it is no longer in your search path. Use a different variable name.

mktemp fails when used in bash script

In Mac OS X, I have no trouble with mktemp when used in Terminal directly, but the same command in a bash script fails. What am I doing wrong?
DIRECTLY:
Air2:~ jk$ mktemp -t "$0"
/var/folders/dq/g6bjxff136515xqlntckj0hc0000gn/T/-bash.74Kw3y9E
SCRIPT:
#!/bin/sh
mktemp -t "$0"
SCRIPT RUN:
Air2:~ jk$ ~/Desktop/Temp/junk.sh
mktemp: mkstemp failed on /var/folders/dq/g6bjxff136515xqlntckj0hc0000gn/T//Users/jk/Desktop/Temp/junk.sh.VrRRi9qE: No such file or directory
Air2:~ jk$
You don't have a directory named /var/folders/dq/g6bjxff136515xqlntckj0hc0000gn/T//Users/jk/Desktop/Temp/.
Notice that $0 is ~/Desktop/Temp/junk.sh when you use it in the bash script and the ~ gets expanded as well. So, rather than creating a simple temporary file in the current directory, mktemp is now trying to create the file in a directory 4 levels deep from the current directory. Since it doesn't exist, your command fails.
From the man page of mktemp:
-t interpret TEMPLATE as a single file name component, relative to a
directory: $TMPDIR, if set; else the directory specified via -p;
else /tmp [deprecated]
So, there you have it from the horse's mount. The parameter to -t should be a single file name component and not a path value.

Resources