I want to set an environment variable that has space in it.
It is a path to a folder and the folder name is:
/home/mehrabib/my video
I edit .bashrc and add the following line to it:
export $VIDEO=/home/mehrabib/my\ video
and run these commands:
echo $VIDEO
cd $VIDEO
The result is:
/home/mehrabib/my video
/home/mehrabib/my :no such file or directory
I change it to
export $VIDEO=/home/mehrabib/my\\\ video
and run these commands:
echo $VIDEO
cd $VIDEO
The result is:
/home/mehrabib/my\ video
/home/mehrabib/my\ :no such file or directory
What should I do?
You should do
export VIDEO="/home/mehrabib/my video"
and to sum Dan's comments up also do
cd "$VIDEO"
which will expand to
cd "/home/mehrabib/my video"
again.
Personally, I've come to prefer the ${VIDEO} syntax.
You can also substitute special characters - use * as a wildcard to substitute for the space.
VIDEO="/home/mehrabib/m*o"
Try to quote VIDEO: cd "$VIDEO".
Related
I have a file file.txt with filenames ending with *.sha256, including the full paths of each file. This is a toy example:
file.txt:
/path/a/9b/x3.sha256
/path/7c/7j/y2.vcf.gz.sha256
/path/e/g/7z.sha256
Each line has a different path/file. The *.sha256 files have checksums.
I want to run the command "sha256sum -c" on each of these *.sha256 files and write the output to an output_file.txt. However, this command only accepts the name of the .sha256 file, not the name including its full path. I have tried the following:
while read in; do
sha256sum -c "$in" >> output_file.txt
done < file.txt
but I get:
"sha256sum: WARNING: 1 listed file could not be read"
which is due to the path included in the command.
Any suggestion is welcome
#!/bin/bash
while read in
do
thedir=$(dirname "$in")
thefile=$(basename "$in")
cd "$thedir"
sha256sum -c "$thefile" >>output_file.txt
done < file.txt
Modify your code to extract the directory and file parts of your in variable.
I have a working shell script that works with no problems but when I executed it with a run script i get the following error:
The script will scan all the proto files in a directory and convert it to Swift using ProtoBuf. After that I will move the swift files into an App folder. The script code is the following
#!/bin/bash
for protoFile in ./*.proto;
do
protoc --swift_out=. $protoFile
done
for file in ./*.swift;
do
mv $file ../Convert\ AV/Model/USBDongle/Proto/
done
Any ideas?
Thank you
I was calling the script from the directory it was located. When Xcode executes the the script that assumption is false. So I am getting the directory where the script is located and I do the logic with that path
#!/bin/bash
#Get Directory where the script is located
baseDirectory=$(dirname "$0")
echo "$baseDirectory"
for protoFile in "$baseDirectory"/*.proto
do
echo $protoFile
protoc --swift_out="$baseDirectory" -I "$baseDirectory" "$protoFile"
done
for protoFileSwift in "$baseDirectory"/*.swift;
do
echo $protoFile
mv "$protoFileSwift" "$baseDirectory"/../Convert\ AV/Model/USBDongle/Proto
done
* /* Makes like is a comment... *
I'm trying to determine the location of the 'flutter' script on a user's computer using this Dart code:
Process.run('which', ['flutter'], runInShell: true).then((results) {
print('which returned code ${results.exitCode}\n StdOut: ${results.stdout}\n StdErr: ${results.stderr}');
}
The problem is that the PATH environment has been set in the user's .bash_profile file like this:
export PATH=$PATH:/Users/mr_pink/dev/flutter/bin
but apparently the .bash_profile script doesn't get loaded when I call Process.run. How can I make sure it is loaded so that the "which flutter" command uses the correct PATH variable?
After reading man bash I found the solution was to add -l to the bash command like this:
Process.run('bash', ['-l', '-c', 'which flutter'])
I am using asset catalog for emoji. The question is, how I could get all emoji file list from asset catalog to prevent hard coded array of file names?
I tried to create run script., but it's not working. creating txt file and put directory path only
for file in "./Images.xcassets/Smiles/"; do
echo $file >> ./Sparkle/smiles.txt
done
Maybe anyone could help me with this or other solution. Thanks
Ok, there is solution to create txt file with specific file list:
Run Script:
rm './Sparkle/smiles.txt'
for file in './YOURAPP/Resources/Images.xcassets/Smiles/smile_*'; do
filename=$(basename $file | cut -f 1 -d '.')
echo -e "$filename\n" > './YOURAPP/smiles.txt'
done
I am trying to save youtube videos as MP3's in my downloads folder. However, this ends up saving files in the same directory as youtube-dl.
youtube-dl --extract-audio --audio-format mp3 --audio-quality=320k
https://www.youtube.com/watch?v=VIDEO_ID
--output C:/Users/Josue/Downloads/%(title)s.%(ext)s
I wanted the videos to save at:
C:/Users/Josue/Downloads/videotitle.mp3
however, they are saving as:
C:/youtube-dl/videotitle-videoID.mp3
Am I doing something incorrectly? I tried reading the documentation on Github, but I was still a bit confused.
I needed to put the options in the following order:
youtube-dl --output C:/Users/Josue/Downloads/%(title)s.%(ext)s
--extract-audio --audio-format mp3
--audio-quality=320k https://www.youtube.com/watch?v=VIDEO_ID
Try:
cd C:\Users\Josue\Downloads
C:\youtube-dl\youtube-dl --etc
This worked for me (for a unix environment):
youtube-dl https://www.youtube.com/watch?v=<video_id> --extract-audio --audio-format mp3 -o '/var/www/html/audio/%(id)s.%(ext)s'
Windows - double %
%%(title)s.%%(ext)s
you can create a configuration file to do this for you , just add those lines to your config file (if you have one, if not create it in C:/Users/Josue youtube-dl.conf) -o C:/Users/Josue/Downloads/%(title)s.%(ext)s .
Link for details