Code: Select all
sudo sed -i -e '/^dtparam=audio/ s/^/# /' /boot/config.txt
Code: Select all
sudo sed -i -e '/^dtparam=audio/ {s/^/# /; a dtparam=hifiberry-dacplus}' /boot/config.txt
Code: Select all
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}"sed" is short for stream editor. Its quite hard to learn (as usual see "man sed"). Of course you can edit files in shell scripts by various means, but take care (and save a backup of the original file first).chito wrote: I read about sed (dont really know what it is) but I wasn't sure that would work with the pi. I read somewhere that shell scripts werent meant to edit files or something like that.
You don't need sed to create a new file.chito wrote:how do i create the new file /etc/asound.conf withCode: Select all
pcm.!default { type hw card 0 } ctl.!default { type hw card 0 }
Code: Select all
cat <<EOF >/etc/asound.conf
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}
EOFCode: Select all
cat <<EOF | sudo tee /etc/asound.conf >/dev/nullYou should be able to shorten that slightly tojahboater wrote:This must be run as root, so try this instead for the first line:-Code: Select all
cat <<EOF | sudo tee /etc/asound.conf >/dev/null
Code: Select all
sudo tee /etc/asound.conf << EOF >/dev/nullYes much better!mfa298 wrote:You should be able to shorten that slightly toCode: Select all
sudo tee /etc/asound.conf << EOF >/dev/null
The other powerful tool that can be useful is awk, for instance you could list the set of configured dtparams and their settings with something like:chito wrote: this is exactly what i needed. with this i think i can make the other changes i need. its certainly heaps to go on.
Code: Select all
pi@pi2:~ $ awk -F= '/^dtparam/ {print $2, $3}' /boot/config.txt
spi on
audio on
Code: Select all
sudo tee /etc/asound.conf << EOF >/dev/null
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}
EOF"man tee" would give you the answers for that one.chito wrote:so what happens when the code to create a new file tries to create it and there's already a file with that name?
will it replace it? if that makes things easier. if not the instructions from hifiberry are to delete it and create a new one
Code: Select all
sudo tee /etc/asound.conf << EOF >/dev/null pcm.!default { type hw card 0 } ctl.!default { type hw card 0 } EOF
Code: Select all
if [ -e /etc/asound.conf ] ; then
echo "File exists"
fiCode: Select all
sudo sed -i -e '/^dtparam=audio/ {s/^/# /; a dtparam=hifiberry-dacplus}' /boot/config.txt
cat <<EOF >/etc/asound.conf
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}
EOFCode: Select all
sudo chmod 0744 /home/pi/mysetup.shCode: Select all
sudo ./mysetup.shCode: Select all
sed: -e expression #1, char 0: unmatched `{'
: not founder.sh: 2: ./mysetup.sh:Code: Select all
sed -i -e '/^dtparam=audio/ s/^/#/' -e '/^#dtparam=audio/a dtparam=hifiberry-dacplus 'Code: Select all
sed: no input files
: not founder.sh: 3: ./mysetup.sh:Code: Select all
sudo sed -i -e '/^dtparam=audio/ s/^/#/' -e '/^#dtparam=audio/a dtparam=hifiberry-dacplus' /boot/config.txtCode: Select all
: No such file or directoryg.txt
: not founder.sh: 3: ./mysetup.sh:
Code: Select all
sudo sed -i -e '/^dtparam=audio/ s/^/#/' -e '/^#dtparam=audio/a dtparam=hifiberry-dacplus' /boot/config.txt
cat <<EOF >/etc/asound.conf
pcm.!default{
type hw card 0
}
ctl.!default {
type hw card 0
}
EOFCode: Select all
sudo sed -i -e '/^dtparam=audio/ s/^/#/' /boot/config.txtCode: Select all
sudo sed -i -e '/^#dtparam=audio/a dtparam=hifiberry-dacplus' /boot/config.txtCode: Select all
No such file or directoryg.txtCode: Select all
sudo sed -i -e '/^dtparam=audio/ s/^/#/' -e '/^#dtparam=audio/a dtparam=hifiberry-dacplus' /home/pi/test.txtCode: Select all
No such file or directoryst.txt